rm(list=ls())

#set working directory -- needs to be updated locally:
setwd("~/Dropbox/Corruption and Political Participation/Corruption and Political Participation/PSRM/Replication Files")

library(foreign)
library(stargazer)
library(ggplot2)
library(gridExtra)

##read in Latinobarometro data:
full <- read.dta("Latinobarometro2013Eng.dta")

ARG <- subset(full,idenpa=="Argentina") #subset to observations from Argentina

##treatment (before vs. after June 13, 2013)
ARG$treat <- ifelse(ARG$diareal<13,0,1)
ARG$treat <- ifelse(ARG$diareal==13,NA,ARG$treat) #coding the day of the event as NA

#for different bandwidths:
ARG$treat7 <- ifelse(ARG$diareal<13 & ARG$diareal>5,0,NA)
ARG$treat7 <- ifelse(ARG$diareal>13 & ARG$diareal<21,1,ARG$treat7)

ARG$treat14 <- ifelse(ARG$diareal<13 & ARG$diareal>0,0,NA)
ARG$treat14 <- ifelse(ARG$diareal>13 & ARG$diareal<28,1,ARG$treat14)

##recode variables for analysis:
#gender:
ARG$male <- ifelse(ARG$S10=="Male",1,0)

#age:
ARG$age <- ARG$S11

#level of education:
ARG$incomplete_highschool <- ifelse(ARG$REEDUC_1=="Illiterate"|ARG$REEDUC_1=="Primary incomplete"|ARG$REEDUC_1=="Primary complete"|ARG$REEDUC_1=="Secundary, intermediate, vocational incomplete",1,0)
ARG$complete_highschool <- ifelse(ARG$REEDUC_1=="Secundary, intermediate, vocational complete",1,0)
ARG$university <- ifelse(ARG$REEDUC_1=="Higher incomplete"|ARG$REEDUC_1=="Higher complete",1,0)

#part of the labor force:
ARG$laborforce <- ifelse(ARG$S19_A=="Self employed"|ARG$S19_A=="Salaried employee in a public company"|ARG$S19_A=="Salaried employee in a private company"|ARG$S19_A=="Temporarily out of work",1,0)
                         
#poverty:
ARG$poverty <- ifelse(ARG$S3=="Never",0,1)
ARG$poverty <- ifelse(ARG$S3=="Don't know",NA,ARG$poverty)
ARG$poverty <- ifelse(ARG$S3=="No answer",NA,ARG$poverty)

#voted in last election:
ARG$voted <- ifelse(ARG$P21TGBSM=="I voted in the last election",1,0)
ARG$voted <- ifelse(ARG$P21TGBSM=="I don’t remember what I did"|ARG$P21TGBSM=="No answer",NA,ARG$voted)

#progress on corruption made:
ARG$progcorrupt <- ifelse(ARG$P69ST=="None",0,NA)
ARG$progcorrupt <- ifelse(ARG$P69ST=="A little",1,ARG$progcorrupt)
ARG$progcorrupt <- ifelse(ARG$P69ST=="Some",2,ARG$progcorrupt)
ARG$progcorrupt <- ifelse(ARG$P69ST=="A great deal",3,ARG$progcorrupt)

#can state solve corruption:
ARG$solvecorrupt <- ifelse(ARG$P72ST_C=="The state cannot solve the problem",0,NA)
ARG$solvecorrupt <- ifelse(ARG$P72ST_C=="A small part of the problem",1,ARG$solvecorrupt)
ARG$solvecorrupt <- ifelse(ARG$P72ST_C=="A large part of the problem",2,ARG$solvecorrupt)
ARG$solvecorrupt <- ifelse(ARG$P72ST_C=="All the problem",3,ARG$solvecorrupt)

#extent of local corruption:
ARG$localcorrupt <- ifelse(ARG$P64GBSM=="No answer"|ARG$P64GBSM=="Don't know",NA,1)
ARG$localcorrupt <- ifelse(ARG$P64GBSM=="Not many officials are involved",2,ARG$localcorrupt)
ARG$localcorrupt <- ifelse(ARG$P64GBSM=="Most officials are corrupt",3,ARG$localcorrupt)
ARG$localcorrupt <- ifelse(ARG$P64GBSM=="Almost everyone is corrupt",4,ARG$localcorrupt)

#extent of national corruption:
ARG$nationalcorrupt <- ifelse(ARG$P65GBS=="No answer"|ARG$P65GBS=="Don't know",NA,1)
ARG$nationalcorrupt <- ifelse(ARG$P65GBS=="Not many officials are involved",2,ARG$nationalcorrupt)
ARG$nationalcorrupt <- ifelse(ARG$P65GBS=="Most officials are corrupt",3,ARG$nationalcorrupt)
ARG$nationalcorrupt <- ifelse(ARG$P65GBS=="Almost everyone is corrupt",4,ARG$nationalcorrupt)

#extent of corruption (national and local combined):
ARG$corrupt <- rowMeans(x=cbind(ARG$localcorrupt,ARG$nationalcorrupt),na.rm = T)

#willingness to demonstrate:
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="Not at all willing",1,NA)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="2",2,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="3",3,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="4",4,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="5",5,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="6",6,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="7",7,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="8",8,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="9",9,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="Very willing",10,ARG$demonstrate_willingness)

#rescaled from 0 to 1:
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="Not at all willing",0,NA)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="2",0.1111111111,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="3",0.2222222222,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="4",0.3333333333,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="5",0.4444444444,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="6",0.5555555555,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="7",0.6666666666,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="8",0.7777777777,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="9",0.8888888888,ARG$demonstrate_willingness)
ARG$demonstrate_willingness <- ifelse(ARG$P31N_E=="Very willing",1,ARG$demonstrate_willingness)

#null vote (voto nulo):
ARG$vote_null <- ifelse(ARG$P22TGBSM=="Vota nulo/Blanco",1,0)
ARG$vote_null <- ifelse(ARG$P22TGBSM=="No responde"|ARG$P22TGBSM=="No inscrito/No tenía edad",NA,ARG$vote_null)

#not voting (staying at home):
ARG$vote_not <- ifelse(ARG$P22TGBSM=="No vota/Ninguno",1,0)
ARG$vote_not <- ifelse(ARG$P22TGBSM=="No responde"|ARG$P22TGBSM=="No inscrito/No tenía edad",NA,ARG$vote_not)

#invalid vote (either null vote or not voting):
ARG$vote_invalid <- ifelse(ARG$vote_null==1 | ARG$vote_not==1, 1, 0)

#PJ supporters:
ARG$vote_PJ <- ifelse(ARG$P22TGBSM=="AR: Partido Justicialista (PJ)",1,0)
ARG$vote_PJ <- ifelse(ARG$P22TGBSM=="No responde"|ARG$P22TGBSM=="No inscrito/No tenía edad",NA,ARG$vote_PJ)

#trust in the judiciary:
ARG$conf_judge <- ifelse(ARG$P26TGB_E=="Lot",3,NA)
ARG$conf_judge <- ifelse(ARG$P26TGB_E=="Some",2,ARG$conf_judge)
ARG$conf_judge <- ifelse(ARG$P26TGB_E=="A little",1,ARG$conf_judge)
ARG$conf_judge <- ifelse(ARG$P26TGB_E=="No trust",0,ARG$conf_judge)

#trust in the political parties:
ARG$conf_parties <- ifelse(ARG$P26TGB_G=="Lot",3,NA)
ARG$conf_parties <- ifelse(ARG$P26TGB_G=="Some",2,ARG$conf_parties)
ARG$conf_parties <- ifelse(ARG$P26TGB_G=="A little",1,ARG$conf_parties)
ARG$conf_parties <- ifelse(ARG$P26TGB_G=="No trust",0,ARG$conf_parties)

#trust in the legislature:
ARG$conf_parl <- ifelse(ARG$P26TGB_C=="Lot",3,NA)
ARG$conf_parl <- ifelse(ARG$P26TGB_C=="Some",2,ARG$conf_parl)
ARG$conf_parl <- ifelse(ARG$P26TGB_C=="A little",1,ARG$conf_parl)
ARG$conf_parl <- ifelse(ARG$P26TGB_C=="No trust",0,ARG$conf_parl)

#trust in the armed forces:
ARG$conf_military <- ifelse(ARG$P28TGB_A=="Lot",3,NA)
ARG$conf_military <- ifelse(ARG$P28TGB_A=="Some",2,ARG$conf_military)
ARG$conf_military <- ifelse(ARG$P28TGB_A=="Little",1,ARG$conf_military)
ARG$conf_military <- ifelse(ARG$P28TGB_A=="Nothing",0,ARG$conf_military)

#trust in the church:
ARG$conf_church <- ifelse(ARG$P28ST_E=="Lot",3,NA)
ARG$conf_church <- ifelse(ARG$P28ST_E=="Some",2,ARG$conf_church)
ARG$conf_church <- ifelse(ARG$P28ST_E=="Little",1,ARG$conf_church)
ARG$conf_church <- ifelse(ARG$P28ST_E=="Nothing",0,ARG$conf_church)


##number of observations in cities with observations on both sides of threshold:

band7 <- subset(ARG,!is.na(ARG$treat7))
cities7T <- unique(subset(band7, band7$treat7==1)$ciudad) #cities in treatment
cities7C <- unique(subset(band7, band7$treat7==0)$ciudad) #cities in control
cities7 <- intersect(cities7T,cities7C) #cities with observations in both treatment and control
band7 <- subset(band7, band7$ciudad %in% cities7) #observations from cities that are in both treatment and control
nrow(band7)

nrow(subset(band7,band7$treat7==1)) #observations in treatment
nrow(subset(band7,band7$treat7==0)) #observations in control

band14 <- subset(ARG,!is.na(ARG$treat14))
cities14T <- unique(subset(band14, band14$treat14==1)$ciudad) #cities in treatment
cities14C <- unique(subset(band14, band14$treat14==0)$ciudad) #cities in control
cities14 <- intersect(cities14T,cities14C) #cities with observations in both treatment and control
band14 <- subset(band14, band14$ciudad %in% cities14) #observations from cities that are in both treatment and control
nrow(band14)

nrow(subset(band14,band14$treat14==1)) #observations in treatment
nrow(subset(band14,band14$treat14==0)) #observations in control


#observations with all covariates (no missingness):

band7_controls <- subset(band7,(!is.na(band7$male) & !is.na(band7$age) & !is.na(band7$incomplete_highschool)& !is.na(band7$complete_highschool) & !is.na(band7$university) & !is.na(band7$laborforce) & !is.na(band7$poverty) & !is.na(band7$voted)))
cities7_controls_T <- unique(subset(band7_controls, band7_controls$treat7==1)$ciudad) #cities in treatment
cities7_controls_C <- unique(subset(band7_controls, band7_controls$treat7==0)$ciudad) #cities in control
cities7_controls <- intersect(cities7_controls_T,cities7_controls_C) #cities with observations in both treatment and control
band7_controls <- subset(band7_controls, band7_controls$ciudad %in% cities7_controls) #observations from cities that are in both treatment and control
nrow(band7_controls)

nrow(subset(band7_controls,band7_controls$treat7==1)) #observations in treatment
nrow(subset(band7_controls,band7_controls$treat7==0)) #observations in control

#for 14 day window:
band14_controls <- subset(band14,(!is.na(band14$male) & !is.na(band14$age) & !is.na(band14$incomplete_highschool)& !is.na(band14$complete_highschool) & !is.na(band14$university) & !is.na(band14$laborforce) & !is.na(band14$poverty) & !is.na(band14$voted)))
cities14_controls_T <- unique(subset(band14_controls, band14_controls$treat14==1)$ciudad) #cities in treatment
cities14_controls_C <- unique(subset(band14_controls, band14_controls$treat14==0)$ciudad) #cities in control
cities14_controls <- intersect(cities14_controls_T,cities14_controls_C) #cities with observations in both treatment and control
band14_controls <- subset(band14_controls, band14_controls$ciudad %in% cities14_controls) #observations from cities that are in both treatment and control
nrow(band14_controls)

nrow(subset(band14_controls,band14_controls$treat14==1)) #observations in treatment
nrow(subset(band14_controls,band14_controls$treat14==0)) #observations in control


##number of valid observations for each covariate:

#age:
band7_controls_age <- subset(band7,!is.na(band7$age))
cities7_controls_T_age <- unique(subset(band7_controls_age, band7_controls_age$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_age <- unique(subset(band7_controls_age, band7_controls_age$treat7==0)$ciudad) #cities in control
cities7_controls_age <- intersect(cities7_controls_T_age,cities7_controls_C_age) #cities with observations in both treatment and control
band7_controls_age <- subset(band7_controls_age, band7_controls_age$ciudad %in% cities7_controls_age) #observations from cities that are in both treatment and control
nrow(band7_controls_age)

#male:
band7_controls_male <- subset(band7,!is.na(band7$male))
cities7_controls_T_male <- unique(subset(band7_controls_male, band7_controls_male$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_male <- unique(subset(band7_controls_male, band7_controls_male$treat7==0)$ciudad) #cities in control
cities7_controls_male <- intersect(cities7_controls_T_male,cities7_controls_C_male) #cities with observations in both treatment and control
band7_controls_male <- subset(band7_controls_male, band7_controls_male$ciudad %in% cities7_controls_male) #observations from cities that are in both treatment and control
nrow(band7_controls_male)

#incomplete_highschool:
band7_controls_incomplete_highschool <- subset(band7,!is.na(band7$incomplete_highschool))
cities7_controls_T_incomplete_highschool <- unique(subset(band7_controls_incomplete_highschool, band7_controls_incomplete_highschool$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_incomplete_highschool <- unique(subset(band7_controls_incomplete_highschool, band7_controls_incomplete_highschool$treat7==0)$ciudad) #cities in control
cities7_controls_incomplete_highschool <- intersect(cities7_controls_T_incomplete_highschool,cities7_controls_C_incomplete_highschool) #cities with observations in both treatment and control
band7_controls_incomplete_highschool <- subset(band7_controls_incomplete_highschool, band7_controls_incomplete_highschool$ciudad %in% cities7_controls_incomplete_highschool) #observations from cities that are in both treatment and control
nrow(band7_controls_incomplete_highschool)

#complete_highschool:
band7_controls_complete_highschool <- subset(band7,!is.na(band7$complete_highschool))
cities7_controls_T_complete_highschool <- unique(subset(band7_controls_complete_highschool, band7_controls_complete_highschool$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_complete_highschool <- unique(subset(band7_controls_complete_highschool, band7_controls_complete_highschool$treat7==0)$ciudad) #cities in control
cities7_controls_complete_highschool <- intersect(cities7_controls_T_complete_highschool,cities7_controls_C_complete_highschool) #cities with observations in both treatment and control
band7_controls_complete_highschool <- subset(band7_controls_complete_highschool, band7_controls_complete_highschool$ciudad %in% cities7_controls_complete_highschool) #observations from cities that are in both treatment and control
nrow(band7_controls_complete_highschool)

#university:
band7_controls_university <- subset(band7,!is.na(band7$university))
cities7_controls_T_university <- unique(subset(band7_controls_university, band7_controls_university$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_university <- unique(subset(band7_controls_university, band7_controls_university$treat7==0)$ciudad) #cities in control
cities7_controls_university <- intersect(cities7_controls_T_university,cities7_controls_C_university) #cities with observations in both treatment and control
band7_controls_university <- subset(band7_controls_university, band7_controls_university$ciudad %in% cities7_controls_university) #observations from cities that are in both treatment and control
nrow(band7_controls_university)

#laborforce:
band7_controls_laborforce <- subset(band7,!is.na(band7$laborforce))
cities7_controls_T_laborforce <- unique(subset(band7_controls_laborforce, band7_controls_laborforce$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_laborforce <- unique(subset(band7_controls_laborforce, band7_controls_laborforce$treat7==0)$ciudad) #cities in control
cities7_controls_laborforce <- intersect(cities7_controls_T_laborforce,cities7_controls_C_laborforce) #cities with observations in both treatment and control
band7_controls_laborforce <- subset(band7_controls_laborforce, band7_controls_laborforce$ciudad %in% cities7_controls_laborforce) #observations from cities that are in both treatment and control
nrow(band7_controls_laborforce)

#poverty:
band7_controls_poverty <- subset(band7,!is.na(band7$poverty))
cities7_controls_T_poverty <- unique(subset(band7_controls_poverty, band7_controls_poverty$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_poverty <- unique(subset(band7_controls_poverty, band7_controls_poverty$treat7==0)$ciudad) #cities in control
cities7_controls_poverty <- intersect(cities7_controls_T_poverty,cities7_controls_C_poverty) #cities with observations in both treatment and control
band7_controls_poverty <- subset(band7_controls_poverty, band7_controls_poverty$ciudad %in% cities7_controls_poverty) #observations from cities that are in both treatment and control
nrow(band7_controls_poverty)

#voted:
band7_controls_voted <- subset(band7,!is.na(band7$voted))
cities7_controls_T_voted <- unique(subset(band7_controls_voted, band7_controls_voted$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_voted <- unique(subset(band7_controls_voted, band7_controls_voted$treat7==0)$ciudad) #cities in control
cities7_controls_voted <- intersect(cities7_controls_T_voted,cities7_controls_C_voted) #cities with observations in both treatment and control
band7_controls_voted <- subset(band7_controls_voted, band7_controls_voted$ciudad %in% cities7_controls_voted) #observations from cities that are in both treatment and control
nrow(band7_controls_voted)


##number of valid observations for each outcome:

#progcorrupt:
band7_controls_progcorrupt <- subset(band7,!is.na(band7$progcorrupt))
cities7_controls_T_progcorrupt <- unique(subset(band7_controls_progcorrupt, band7_controls_progcorrupt$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_progcorrupt <- unique(subset(band7_controls_progcorrupt, band7_controls_progcorrupt$treat7==0)$ciudad) #cities in control
cities7_controls_progcorrupt <- intersect(cities7_controls_T_progcorrupt,cities7_controls_C_progcorrupt) #cities with observations in both treatment and control
band7_controls_progcorrupt <- subset(band7_controls_progcorrupt, band7_controls_progcorrupt$ciudad %in% cities7_controls_progcorrupt) #observations from cities that are in both treatment and control
nrow(band7_controls_progcorrupt)

#solvecorrupt:
band7_controls_solvecorrupt <- subset(band7,!is.na(band7$solvecorrupt))
cities7_controls_T_solvecorrupt <- unique(subset(band7_controls_solvecorrupt, band7_controls_solvecorrupt$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_solvecorrupt <- unique(subset(band7_controls_solvecorrupt, band7_controls_solvecorrupt$treat7==0)$ciudad) #cities in control
cities7_controls_solvecorrupt <- intersect(cities7_controls_T_solvecorrupt,cities7_controls_C_solvecorrupt) #cities with observations in both treatment and control
band7_controls_solvecorrupt <- subset(band7_controls_solvecorrupt, band7_controls_solvecorrupt$ciudad %in% cities7_controls_solvecorrupt) #observations from cities that are in both treatment and control
nrow(band7_controls_solvecorrupt)

#corrupt:
band7_controls_corrupt <- subset(band7,!is.na(band7$corrupt))
cities7_controls_T_corrupt <- unique(subset(band7_controls_corrupt, band7_controls_corrupt$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_corrupt <- unique(subset(band7_controls_corrupt, band7_controls_corrupt$treat7==0)$ciudad) #cities in control
cities7_controls_corrupt <- intersect(cities7_controls_T_corrupt,cities7_controls_C_corrupt) #cities with observations in both treatment and control
band7_controls_corrupt <- subset(band7_controls_corrupt, band7_controls_corrupt$ciudad %in% cities7_controls_corrupt) #observations from cities that are in both treatment and control
nrow(band7_controls_corrupt)

#demonstrate_willingness:
band7_controls_demonstrate_willingness <- subset(band7,!is.na(band7$demonstrate_willingness))
cities7_controls_T_demonstrate_willingness <- unique(subset(band7_controls_demonstrate_willingness, band7_controls_demonstrate_willingness$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_demonstrate_willingness <- unique(subset(band7_controls_demonstrate_willingness, band7_controls_demonstrate_willingness$treat7==0)$ciudad) #cities in control
cities7_controls_demonstrate_willingness <- intersect(cities7_controls_T_demonstrate_willingness,cities7_controls_C_demonstrate_willingness) #cities with observations in both treatment and control
band7_controls_demonstrate_willingness <- subset(band7_controls_demonstrate_willingness, band7_controls_demonstrate_willingness$ciudad %in% cities7_controls_demonstrate_willingness) #observations from cities that are in both treatment and control
nrow(band7_controls_demonstrate_willingness)

#vote_invalid:
band7_controls_vote_invalid <- subset(band7,!is.na(band7$vote_invalid))
cities7_controls_T_vote_invalid <- unique(subset(band7_controls_vote_invalid, band7_controls_vote_invalid$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_vote_invalid <- unique(subset(band7_controls_vote_invalid, band7_controls_vote_invalid$treat7==0)$ciudad) #cities in control
cities7_controls_vote_invalid <- intersect(cities7_controls_T_vote_invalid,cities7_controls_C_vote_invalid) #cities with observations in both treatment and control
band7_controls_vote_invalid <- subset(band7_controls_vote_invalid, band7_controls_vote_invalid$ciudad %in% cities7_controls_vote_invalid) #observations from cities that are in both treatment and control
nrow(band7_controls_vote_invalid)

#conf_judge:
band7_controls_conf_judge <- subset(band7,!is.na(band7$conf_judge))
cities7_controls_T_conf_judge <- unique(subset(band7_controls_conf_judge, band7_controls_conf_judge$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_conf_judge <- unique(subset(band7_controls_conf_judge, band7_controls_conf_judge$treat7==0)$ciudad) #cities in control
cities7_controls_conf_judge <- intersect(cities7_controls_T_conf_judge,cities7_controls_C_conf_judge) #cities with observations in both treatment and control
band7_controls_conf_judge <- subset(band7_controls_conf_judge, band7_controls_conf_judge$ciudad %in% cities7_controls_conf_judge) #observations from cities that are in both treatment and control
nrow(band7_controls_conf_judge)

#conf_parties:
band7_controls_conf_parties <- subset(band7,!is.na(band7$conf_parties))
cities7_controls_T_conf_parties <- unique(subset(band7_controls_conf_parties, band7_controls_conf_parties$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_conf_parties <- unique(subset(band7_controls_conf_parties, band7_controls_conf_parties$treat7==0)$ciudad) #cities in control
cities7_controls_conf_parties <- intersect(cities7_controls_T_conf_parties,cities7_controls_C_conf_parties) #cities with observations in both treatment and control
band7_controls_conf_parties <- subset(band7_controls_conf_parties, band7_controls_conf_parties$ciudad %in% cities7_controls_conf_parties) #observations from cities that are in both treatment and control
nrow(band7_controls_conf_parties)

#conf_parl:
band7_controls_conf_parl <- subset(band7,!is.na(band7$conf_parl))
cities7_controls_T_conf_parl <- unique(subset(band7_controls_conf_parl, band7_controls_conf_parl$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_conf_parl <- unique(subset(band7_controls_conf_parl, band7_controls_conf_parl$treat7==0)$ciudad) #cities in control
cities7_controls_conf_parl <- intersect(cities7_controls_T_conf_parl,cities7_controls_C_conf_parl) #cities with observations in both treatment and control
band7_controls_conf_parl <- subset(band7_controls_conf_parl, band7_controls_conf_parl$ciudad %in% cities7_controls_conf_parl) #observations from cities that are in both treatment and control
nrow(band7_controls_conf_parl)


##number of valid observations with data for all covariates and outcomes:
band7_controls_full <- subset(band7,!is.na(age) & !is.na(male) & !is.na(incomplete_highschool) & !is.na(complete_highschool) & !is.na(university) & !is.na(laborforce) & !is.na(poverty) & !is.na(voted) & !is.na(progcorrupt) & !is.na(solvecorrupt) & !is.na(corrupt) & !is.na(demonstrate_willingness) & !is.na(vote_invalid) & !is.na(conf_judge) & !is.na(conf_parties) & !is.na(conf_parl))
cities7_controls_T_full <- unique(subset(band7_controls_full, band7_controls_full$treat7==1)$ciudad) #cities in treatment
cities7_controls_C_full <- unique(subset(band7_controls_full, band7_controls_full$treat7==0)$ciudad) #cities in control
cities7_controls_full <- intersect(cities7_controls_T_full,cities7_controls_C_full) #cities with observations in both treatment and control
band7_controls_full <- subset(band7_controls_full, band7_controls_full$ciudad %in% cities7_controls_full) #observations from cities that are in both treatment and control
nrow(band7_controls_full)

nrow(subset(band7_controls_full,band7_controls_full$treat7==1)) #observations in treatment
nrow(subset(band7_controls_full,band7_controls_full$treat7==0)) #observations in control

#for 14 days:
band14_controls_full <- subset(band14,!is.na(age) & !is.na(male) & !is.na(incomplete_highschool) & !is.na(complete_highschool) & !is.na(university) & !is.na(laborforce) & !is.na(poverty) & !is.na(voted) & !is.na(progcorrupt) & !is.na(solvecorrupt) & !is.na(corrupt) & !is.na(demonstrate_willingness) & !is.na(vote_invalid) & !is.na(conf_judge) & !is.na(conf_parties) & !is.na(conf_parl))
cities14_controls_T_full <- unique(subset(band14_controls_full, band14_controls_full$treat14==1)$ciudad) #cities in treatment
cities14_controls_C_full <- unique(subset(band14_controls_full, band14_controls_full$treat14==0)$ciudad) #cities in control
cities14_controls_full <- intersect(cities14_controls_T_full,cities14_controls_C_full) #cities with observations in both treatment and control
band14_controls_full <- subset(band14_controls_full, band14_controls_full$ciudad %in% cities14_controls_full) #observations from cities that are in both treatment and control
nrow(band14_controls_full)

nrow(subset(band14_controls_full,band14_controls_full$treat14==1)) #observations in treatment
nrow(subset(band14_controls_full,band14_controls_full$treat14==0)) #observations in control


###balance tests:
##Table A5:

balance <- 
rbind(
  c("age",
    summary(lm(age ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(age ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$age),1,0)),
    nrow(band7_controls_age)),
  c("male",
    summary(lm(male ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(male ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$male),1,0)),
    nrow(band7_controls_male)),
  c("incomplete_highschool",
    summary(lm(incomplete_highschool ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(incomplete_highschool ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$incomplete_highschool),1,0)),
    nrow(band7_controls_incomplete_highschool)),
  c("complete_highschool",
    summary(lm(complete_highschool ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(complete_highschool ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$complete_highschool),1,0)),
    nrow(band7_controls_complete_highschool)),
  c("university",
    summary(lm(university ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(university ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$university),1,0)),
    nrow(band7_controls_university)),
  c("laborforce",
    summary(lm(laborforce ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(laborforce ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$laborforce),1,0)),
    nrow(band7_controls_laborforce)),
  c("poverty",
    summary(lm(poverty ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(poverty ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$poverty),1,0)),
    nrow(band7_controls_poverty)),
  c("voted",
    summary(lm(voted ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(voted ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$voted),1,0)),
    nrow(band7_controls_voted))
)
balance <- cbind(balance[,c(1:2)],rowSums(cbind(as.numeric(balance[,2]),as.numeric(balance[,3]))),balance[,c(3:7)])

colnames(balance) <- c("Variable","Control","Treatment","Diff. means","SE", "p-value", "Valid N","Analytic N")
balance[,2] <- round(as.numeric(balance[,2]),digits=3)
balance[,3] <- round(as.numeric(balance[,3]),digits=3)
balance[,4] <- round(as.numeric(balance[,4]),digits=3)
balance[,5] <- round(as.numeric(balance[,5]),digits=3)
balance[,6] <- round(as.numeric(balance[,6]),digits=3)

balance.table <- balance[,c(1:4,6:8)]

#Table A5:
stargazer(balance.table, out="TableA5.tex")


###descriptive statistics for outcomes:

##for all observations
##Table A1:

descriptives <- rbind(
c("progcorrupt",min(ARG$progcorrupt,na.rm=T),max(ARG$progcorrupt,na.rm=T),mean(ARG$progcorrupt,na.rm=T),median(ARG$progcorrupt,na.rm=T),sum(!is.na(ARG$progcorrupt))),
c("solvecorrupt",min(ARG$solvecorrupt,na.rm=T),max(ARG$solvecorrupt,na.rm=T),mean(ARG$solvecorrupt,na.rm=T),median(ARG$solvecorrupt,na.rm=T),sum(!is.na(ARG$solvecorrupt))),
c("corrupt",min(ARG$corrupt,na.rm=T),max(ARG$corrupt,na.rm=T),mean(ARG$corrupt,na.rm=T),median(ARG$corrupt,na.rm=T),sum(!is.na(ARG$corrupt))),
c("demonstrate_willingness",min(ARG$demonstrate_willingness,na.rm=T),max(ARG$demonstrate_willingness,na.rm=T),mean(ARG$demonstrate_willingness,na.rm=T),median(ARG$demonstrate_willingness,na.rm=T),sum(!is.na(ARG$demonstrate_willingness))),
c("vote_invalid",min(ARG$vote_invalid,na.rm=T),max(ARG$vote_invalid,na.rm=T),mean(ARG$vote_invalid,na.rm=T),median(ARG$vote_invalid,na.rm=T),sum(!is.na(ARG$vote_invalid))),
c("conf_judge",min(ARG$conf_judge,na.rm=T),max(ARG$conf_judge,na.rm=T),mean(ARG$conf_judge,na.rm=T),median(ARG$conf_judge,na.rm=T),sum(!is.na(ARG$conf_judge))),
c("conf_parties",min(ARG$conf_parties,na.rm=T),max(ARG$conf_parties,na.rm=T),mean(ARG$conf_parties,na.rm=T),median(ARG$conf_parties,na.rm=T),sum(!is.na(ARG$conf_parties))),
c("conf_parl",min(ARG$conf_parl,na.rm=T),max(ARG$conf_parl,na.rm=T),mean(ARG$conf_parl,na.rm=T),median(ARG$conf_parl,na.rm=T),sum(!is.na(ARG$conf_parl)))
)

colnames(descriptives) <- c("Variable","Minimum","Maximum","Mean","Median","Valid N")
descriptives[,4] <- round(as.numeric(descriptives[,4]),3)
descriptives[,5] <- round(as.numeric(descriptives[,5]),3)

descriptives

#Table A1:
stargazer(descriptives, out="TableA1.tex")


##for analytic sample:
##Table A2:
descriptives_analytic <- rbind(
  c("progcorrupt",min(band7_controls_progcorrupt$progcorrupt,na.rm=T),max(band7_controls_progcorrupt$progcorrupt,na.rm=T),mean(band7_controls_progcorrupt$progcorrupt,na.rm=T),median(band7_controls_progcorrupt$progcorrupt,na.rm=T),sum(!is.na(band7_controls_progcorrupt$progcorrupt))),
  c("solvecorrupt",min(band7_controls_solvecorrupt$solvecorrupt,na.rm=T),max(band7_controls_solvecorrupt$solvecorrupt,na.rm=T),mean(band7_controls_solvecorrupt$solvecorrupt,na.rm=T),median(band7_controls_solvecorrupt$solvecorrupt,na.rm=T),sum(!is.na(band7_controls_solvecorrupt$solvecorrupt))),
  c("corrupt",min(band7_controls_corrupt$corrupt,na.rm=T),max(band7_controls_corrupt$corrupt,na.rm=T),mean(band7_controls_corrupt$corrupt,na.rm=T),median(band7_controls_corrupt$corrupt,na.rm=T),sum(!is.na(band7_controls_corrupt$corrupt))),
  c("demonstrate_willingness",min(band7_controls_demonstrate_willingness$demonstrate_willingness,na.rm=T),max(band7_controls_demonstrate_willingness$demonstrate_willingness,na.rm=T),mean(band7_controls_demonstrate_willingness$demonstrate_willingness,na.rm=T),median(band7_controls_demonstrate_willingness$demonstrate_willingness,na.rm=T),sum(!is.na(band7_controls_demonstrate_willingness$demonstrate_willingness))),
  c("vote_invalid",min(band7_controls_vote_invalid$vote_invalid,na.rm=T),max(band7_controls_vote_invalid$vote_invalid,na.rm=T),mean(band7_controls_vote_invalid$vote_invalid,na.rm=T),median(band7_controls_vote_invalid$vote_invalid,na.rm=T),sum(!is.na(band7_controls_vote_invalid$vote_invalid))),
  c("conf_judge",min(band7_controls_conf_judge$conf_judge,na.rm=T),max(band7_controls_conf_judge$conf_judge,na.rm=T),mean(band7_controls_conf_judge$conf_judge,na.rm=T),median(band7_controls_conf_judge$conf_judge,na.rm=T),sum(!is.na(band7_controls_conf_judge$conf_judge))),
  c("conf_parties",min(band7_controls_conf_parties$conf_parties,na.rm=T),max(band7_controls_conf_parties$conf_parties,na.rm=T),mean(band7_controls_conf_parties$conf_parties,na.rm=T),median(band7_controls_conf_parties$conf_parties,na.rm=T),sum(!is.na(band7_controls_conf_parties$conf_parties))),
  c("conf_parl",min(band7_controls_conf_parl$conf_parl,na.rm=T),max(band7_controls_conf_parl$conf_parl,na.rm=T),mean(band7_controls_conf_parl$conf_parl,na.rm=T),median(band7_controls_conf_parl$conf_parl,na.rm=T),sum(!is.na(band7_controls_conf_parl$conf_parl)))
)

colnames(descriptives_analytic) <- c("Variable","Minimum","Maximum","Mean","Median","Valid N")
descriptives_analytic[,4] <- round(as.numeric(descriptives_analytic[,4]),3)
descriptives_analytic[,5] <- round(as.numeric(descriptives_analytic[,5]),3)

descriptives_analytic

#Table A2:
stargazer(descriptives_analytic, out="TableA2.tex")


###treatment effects for main outcomes (without covariates):
###Table A8:
outcomes <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$progcorrupt),1,0)),
    summary(lm(progcorrupt ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$progcorrupt),1,0))),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$solvecorrupt),1,0)),
    summary(lm(solvecorrupt ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$solvecorrupt),1,0))),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$corrupt),1,0)),
    summary(lm(corrupt ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(corrupt ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$corrupt),1,0))),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$demonstrate_willingness),1,0)),
    summary(lm(demonstrate_willingness ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$demonstrate_willingness),1,0))),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$vote_null),1,0)),
    summary(lm(vote_null ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_null ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$vote_null),1,0))),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$vote_not),1,0)),
    summary(lm(vote_not ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_not ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$vote_not),1,0))),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$vote_invalid),1,0)),
    summary(lm(vote_invalid ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$vote_invalid),1,0))),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$conf_judge),1,0)),
    summary(lm(conf_judge ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_judge ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$conf_judge),1,0))),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$conf_parties),1,0)),
    summary(lm(conf_parties ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parties ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$conf_parties),1,0))),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$conf_parl),1,0)),
    summary(lm(conf_parl ~ treat14 + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parl ~ treat14 + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$conf_parl),1,0)))
)

colnames(outcomes) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7","Intercept14","Estimate14","SE14","pvalue14","ValidN14")

table_without_controls <- outcomes[,c(1,3,4:6)]
table_without_controls <- as.data.frame(table_without_controls)
table_without_controls[,2] <- round(as.numeric(as.character(table_without_controls[,2])),3)
table_without_controls[,3] <- round(as.numeric(as.character(table_without_controls[,3])),3)
table_without_controls[,4] <- round(as.numeric(as.character(table_without_controls[,4])),3)

table_without_controls <- table_without_controls[c(1:4,7:10),]

table_without_controls[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(table_without_controls) <- c("Variable","Effect","SE","p Value", "N")

#Table A8:
stargazer(as.matrix(table_without_controls),rownames = F, out="TableA8.tex")


###treatment effects for main outcomes (with covariates):
##Table A7:
outcomes_controls <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$progcorrupt),1,0)),
    summary(lm(progcorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$progcorrupt),1,0))),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$solvecorrupt),1,0)),
    summary(lm(solvecorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$solvecorrupt),1,0))),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$corrupt),1,0)),
    summary(lm(corrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(corrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$corrupt),1,0))),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$demonstrate_willingness),1,0)),
    summary(lm(demonstrate_willingness ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$demonstrate_willingness),1,0))),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$vote_null),1,0)),
    summary(lm(vote_null ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_null ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$vote_null),1,0))),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$vote_not),1,0)),
    summary(lm(vote_not ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_not ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$vote_not),1,0))),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$vote_invalid),1,0)),
    summary(lm(vote_invalid ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$vote_invalid),1,0))),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$conf_judge),1,0)),
    summary(lm(conf_judge ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_judge ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$conf_judge),1,0))),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$conf_parties),1,0)),
    summary(lm(conf_parties ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parties ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$conf_parties),1,0))),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$conf_parl),1,0)),
    summary(lm(conf_parl ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parl ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat14==0|ARG$treat14==1)$conf_parl),1,0)))
)

colnames(outcomes_controls) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7","Intercept14","Estimate14","SE14","pvalue14","ValidN14")

table_appendix <- outcomes_controls[,c(1,3,4:6)]
table_appendix[,2] <- round(as.numeric(table_appendix[,2]),3)
table_appendix[,3] <- round(as.numeric(table_appendix[,3]),3)
table_appendix[,4] <- round(as.numeric(table_appendix[,4]),3) 

table_appendix <- as.data.frame(table_appendix[c(1:4,7:10),])

table_appendix[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

table_appendix$Variable[table_appendix$Variable=="progcorrupt"] <- "Progress on state corruption"
table_appendix$Variable[table_appendix$Variable=="solvecorrupt"] <- "State's ability to solve corruption"
table_appendix$Variable[table_appendix$Variable=="corrupt"] <- "Prevalence of corruption"
table_appendix$Variable[table_appendix$Variable=="demonstrate_willingness"] <- "Demonstrate"
table_appendix$Variable[table_appendix$Variable=="vote_invalid"] <- "Invalid vote"
table_appendix$Variable[table_appendix$Variable=="conf_judge"] <- "Trust in judiciary"
table_appendix$Variable[table_appendix$Variable=="conf_parties"] <- "Trust in parties"
table_appendix$Variable[table_appendix$Variable=="conf_parl"] <- "Trust in congress"

colnames(table_appendix) <- c("Variable","Effect","SE","p Value", "N")

#Table A7:
stargazer(as.matrix(table_appendix),rownames = F, out="TableA7.tex")


###CREATE FIGURES
##merge dataframes
colnames(outcomes) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7","Intercept14","Estimate14","SE14","pvalue14","ValidN14")
outcomes <- as.data.frame(outcomes)
outcomes$Estimate7 <- as.numeric(as.character(outcomes$Estimate7))
outcomes$SE7 <- as.numeric(as.character(outcomes$SE7))
outcomes$pvalue7 <- as.numeric(as.character(outcomes$pvalue7))
outcomes$Estimate14 <- as.numeric(as.character(outcomes$Estimate14))
outcomes$SE14 <- as.numeric(as.character(outcomes$SE14))
outcomes$pvalue14 <- as.numeric(as.character(outcomes$pvalue14))
outcomes$Variable <- as.character(outcomes$Variable)
outcomes$controls <- "Without controls"

outcomes_7 <- outcomes[,c(1:6,12)]
colnames(outcomes_7)[2:6] <- c("Intercept","Estimate","SE","pvalue","ValidN")
outcomes_7$bandwidth <- "7 days"

outcomes_14 <- outcomes[,c(1,7:12)]
colnames(outcomes_14)[2:6] <- c("Intercept","Estimate","SE","pvalue","ValidN")
outcomes_14$bandwidth <- "14 days"
outcomes_combined <- rbind(outcomes_7,outcomes_14)

colnames(outcomes_controls) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7","Intercept14","Estimate14","SE14","pvalue14","ValidN14")
outcomes_controls <- as.data.frame(outcomes_controls)
outcomes_controls$Estimate7 <- as.numeric(as.character(outcomes_controls$Estimate7))
outcomes_controls$SE7 <- as.numeric(as.character(outcomes_controls$SE7))
outcomes_controls$pvalue7 <- as.numeric(as.character(outcomes_controls$pvalue7))
outcomes_controls$Estimate14 <- as.numeric(as.character(outcomes_controls$Estimate14))
outcomes_controls$SE14 <- as.numeric(as.character(outcomes_controls$SE14))
outcomes_controls$pvalue14 <- as.numeric(as.character(outcomes_controls$pvalue14))
outcomes_controls$Variable <- as.character(outcomes_controls$Variable)
outcomes_controls$controls <- "With controls"

outcomes_controls_7 <- outcomes_controls[,c(1:6,12)]
colnames(outcomes_controls_7)[2:6] <- c("Intercept","Estimate","SE","pvalue","ValidN")
outcomes_controls_7$bandwidth <- "7 days"

outcomes_controls_14 <- outcomes_controls[,c(1,7:12)]
colnames(outcomes_controls_14)[2:6] <- c("Intercept","Estimate","SE","pvalue","ValidN")
outcomes_controls_14$bandwidth <- "14 days"

outcomes_combined <- rbind(outcomes_combined,outcomes_controls_7,outcomes_controls_14)

outcomes_combined$Variable[c(5:7)] <- c("Vote null", "Not vote", "Invalid vote")
outcomes_combined$Variable[c(25:27)] <- c("Vote null", "Not vote", "Invalid vote")
outcomes_combined$Variable[c(15:17)] <- c("Vote null", "Not vote", "Invalid vote")
outcomes_combined$Variable[c(35:37)] <- c("Vote null", "Not vote", "Invalid vote")

outcomes_combined$Variable[c(8:10)] <- c("Trust in judiciary","Trust in parties","Trust in congress")
outcomes_combined$Variable[c(28:30)] <- c("Trust in judiciary","Trust in parties","Trust in congress")
outcomes_combined$Variable[c(18:20)] <- c("Trust in judiciary","Trust in parties","Trust in congress")
outcomes_combined$Variable[c(38:40)] <- c("Trust in judiciary","Trust in parties","Trust in congress")

ARG_outcomes <- outcomes_combined
rownames(ARG_outcomes) <- c(1:nrow(ARG_outcomes))

ARG_outcomes$Variable <- as.character(ARG_outcomes$Variable)
ARG_outcomes$Variable[ARG_outcomes$Variable=="progcorrupt"] <- "Progress on\nstate corruption"
ARG_outcomes$Variable[ARG_outcomes$Variable=="solvecorrupt"] <- "State's ability to\nsolve corruption"
ARG_outcomes$Variable[ARG_outcomes$Variable=="corrupt"] <- "Prevalence of\ncorruption"
ARG_outcomes$Variable[ARG_outcomes$Variable=="demonstrate_willingness"] <- "Demonstrate"
ARG_outcomes$Variable[ARG_outcomes$Variable=="Invalid vote"] <- "Invalid\nvote"
ARG_outcomes$Variable <- as.factor(ARG_outcomes$Variable)
ARG_outcomes$Variable <- factor(ARG_outcomes$Variable,levels = c("Trust in judiciary", "Trust in parties", "Trust in congress","Prevalence of\ncorruption","Progress on\nstate corruption","State's ability to\nsolve corruption","Vote null","Not vote", "Invalid\nvote","Demonstrate"))


##Figure 2: Trust in Parl & Parties & Judiciary:
ggplot(ARG_outcomes[c(29:30,28,9:10,8),], aes(fill=controls,y=Estimate,x=Variable))+
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Change in\nattitudes/beliefs")+
  xlab("")+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.2,0.3,0.4), limits=c(-0.5,0.025))+
  theme(legend.position = "bottom",legend.title = element_blank())+
  geom_point(aes(colour=controls,shape=controls),size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.90)/2)), ymin=Estimate - (SE*-qnorm((1-0.90)/2)),colour=controls), width=.15, position=position_dodge(.9),stat="identity",size=0.8)+
  geom_errorbar(aes(ymax=Estimate + (SE*(-qnorm((1-0.95)/2))), ymin=Estimate - (SE*(-qnorm((1-0.95)/2))),colour=controls), width=.0, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("Figure2.pdf", width = 9, height = 4)


##Figure 3: Prevalence of corruptions, perceptions of progress on corruption, and the state's ability to fight corruption:
ggplot(ARG_outcomes[c(23,21,22,3,11,12),], aes(fill=controls,y=Estimate,x=Variable))+
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Change in\nattitudes/beliefs")+
  xlab("")+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.2,0.3,0.4,0.5), limits=c(-0.5,0.5))+
  theme(legend.position = "bottom",legend.title = element_blank())+
  geom_point(aes(colour=controls,shape=controls),size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.90)/2)), ymin=Estimate - (SE*-qnorm((1-0.90)/2)),colour=controls), width=.15, position=position_dodge(.9),stat="identity",size=0.8)+
  geom_errorbar(aes(ymax=Estimate + (SE*(-qnorm((1-0.95)/2))), ymin=Estimate - (SE*(-qnorm((1-0.95)/2))),colour=controls), width=.0, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("Figure3.pdf", width = 9, height = 5)

##Figure 4: Political engagement
ggplot(ARG_outcomes[c(27,24,7,4),], aes(fill=controls,y=Estimate,x=Variable)) +
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Change in \nbehavior/attitude")+
  xlab("")+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1,0.2), limits=c(-0.25,0.25))+
  theme(legend.position = "bottom",legend.title = element_blank())+
  geom_point(aes(colour=controls,shape=controls),size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.90)/2)), ymin=Estimate - (SE*-qnorm((1-0.90)/2)),colour=controls), width=.15, position=position_dodge(.9),stat="identity",size=0.8)+
  geom_errorbar(aes(ymax=Estimate + (SE*(-qnorm((1-0.95)/2))), ymin=Estimate - (SE*(-qnorm((1-0.95)/2))),colour=controls), width=.0, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("Figure4.pdf", width = 9, height = 4)


##For the online appendix:

ARG_outcomes$controls[c(1:10)] <- "Without controls\n(7 days)"
ARG_outcomes$controls[c(21:30)] <- "With controls\n(7 days)"
ARG_outcomes$controls[c(11:20)] <- "Without controls\n(14 days)"
ARG_outcomes$controls[c(31:40)] <- "With controls\n(14 days)"

ARG_outcomes$controls <- factor(ARG_outcomes$controls,levels = c("With controls\n(7 days)","Without controls\n(7 days)","With controls\n(14 days)","Without controls\n(14 days)"))

#Figure A1:
ggplot(ARG_outcomes[c(23,3,33,13,21,1,31,11,22,2,32,12),], aes(fill=controls,y=Estimate,x=Variable)) +
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("\nChange in perceiption")+
  xlab("")+
  scale_color_manual(values=c("darkblue", "red","red","red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "bottom",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.2,0.3,0.4,0.5), limits=c(-0.5,0.5))+
  geom_point(aes(colour=controls,shape=controls),size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.90)/2)), ymin=Estimate - (SE*-qnorm((1-0.90)/2)),colour=controls), width=.15, position=position_dodge(.9),stat="identity",size=0.8)+
  geom_errorbar(aes(ymax=Estimate + (SE*(-qnorm((1-0.95)/2))), ymin=Estimate - (SE*(-qnorm((1-0.95)/2))),colour=controls), width=.0, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("FigureA1.pdf", width = 11, height = 6)


#Figure A2:
ggplot(ARG_outcomes[c(28,8,38,18,29,9,39,19,30,10,40,20),], aes(fill=controls,y=Estimate,x=Variable)) +
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("\nChange in trust")+
  xlab("")+
  scale_color_manual(values=c("darkblue", "red","red","red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "bottom",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.2,0.3,0.4,0.5), limits=c(-0.5,0.05))+
  geom_point(aes(colour=controls,shape=controls),size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.90)/2)), ymin=Estimate - (SE*-qnorm((1-0.90)/2)),colour=controls), width=.15, position=position_dodge(.9),stat="identity",size=0.8)+
  geom_errorbar(aes(ymax=Estimate + (SE*(-qnorm((1-0.95)/2))), ymin=Estimate - (SE*(-qnorm((1-0.95)/2))),colour=controls), width=.0, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("FigureA2.pdf", width = 11, height = 4)


#combined behavioral outcomes:
#Figure A3:
ggplot(ARG_outcomes[c(25,5,35,15,26,6,36,16,27,7,37,17,24,4,34,14),], aes(fill=controls,y=Estimate,x=Variable)) +
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Change in \nbehavior/attitude")+
  xlab("")+
  scale_color_manual(values=c("darkblue", "red","red","red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "bottom",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.2,-0.15,-0.1,-0.05,0,0.05,0.1,0.15,0.2), limits=c(-0.2,0.2))+
  geom_point(aes(colour=controls,shape=controls),size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.90)/2)), ymin=Estimate - (SE*-qnorm((1-0.90)/2)),colour=controls), width=.2, position=position_dodge(.9),stat="identity",size=0.8)+
  geom_errorbar(aes(ymax=Estimate + (SE*(-qnorm((1-0.95)/2))), ymin=Estimate - (SE*(-qnorm((1-0.95)/2))),colour=controls), width=.0, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("FigureA3.pdf", width = 11, height = 5)


##Placebo tests: effect on other institutional outcomes:
##Table A21:
other_institutions <- rbind(
  c("conf_military",
    summary(lm(conf_military ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_military ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$conf_military),1,0))
    ),
  c("conf_church",
    summary(lm(conf_church ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_church ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$treat7==0|ARG$treat7==1)$conf_church),1,0))
    ))

colnames(other_institutions) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

other_institutions_appendix <- other_institutions[,c(1,3,4:6)]
other_institutions_appendix[,2] <- round(as.numeric(other_institutions_appendix[,2]),3)
other_institutions_appendix[,3] <- round(as.numeric(other_institutions_appendix[,3]),3)
other_institutions_appendix[,4] <- round(as.numeric(other_institutions_appendix[,4]),3) 

other_institutions_appendix <- as.data.frame(other_institutions_appendix)

other_institutions_appendix[,1] <- c("Trust in armed forces",
                                     "Trust in church")

colnames(other_institutions_appendix) <- c("Variable","Effect","SE","p Value", "N")

#Table A21:
stargazer(as.matrix(other_institutions_appendix), out="TableA21.tex")


##Effects for main outcomes without PJ supporters:
##Table A11:

ARG_withoutPJ <- subset(ARG,ARG$vote_PJ!=1)

outcomes_withoutPJ <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$progcorrupt),1,0))),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$solvecorrupt),1,0))),
  c("corrupt",
    summary(lm(corrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(corrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$corrupt),1,0))),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$demonstrate_willingness),1,0))),
  c("vote_null",
    summary(lm(vote_null ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(vote_null ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$vote_null),1,0))),
  c("vote_not",
    summary(lm(vote_not ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(vote_not ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$vote_not),1,0))),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$vote_invalid),1,0))),
  c("conf_judge",
    summary(lm(conf_judge ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(conf_judge ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$conf_judge),1,0))),
  c("conf_parties",
    summary(lm(conf_parties ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(conf_parties ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$conf_parties),1,0))),
  c("conf_parl",
    summary(lm(conf_parl ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[1,1],
    summary(lm(conf_parl ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_withoutPJ))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_withoutPJ,ARG_withoutPJ$treat14==0|ARG_withoutPJ$treat14==1)$conf_parl),1,0)))
)

colnames(outcomes_withoutPJ) <- c("Variable",
                                  "Intercept14","Estimate14","SE14","pvalue14","ValidN14")

outcomes_withoutPJ

table_withoutPJ <- outcomes_withoutPJ[,c(1,3:6)]
table_withoutPJ[,2] <- round(as.numeric(table_withoutPJ[,2]),3)
table_withoutPJ[,3] <- round(as.numeric(table_withoutPJ[,3]),3)
table_withoutPJ[,4] <- round(as.numeric(table_withoutPJ[,4]),3) 

table_withoutPJ <- as.data.frame(table_withoutPJ[c(1:4,7:10),])

table_withoutPJ[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(table_withoutPJ) <- c("Variable","Effect","SE","p Value", "N")

#Table A11:
stargazer(as.matrix(table_withoutPJ), out="TableA11.tex")

##analytic sample: valid observations with data for all covariates and outcomes:
band14_withoutPJ_controls_full <- subset(band14,!is.na(age) & !is.na(male) & !is.na(incomplete_highschool) & !is.na(complete_highschool) & !is.na(university) & !is.na(laborforce) & !is.na(poverty) & !is.na(voted) & !is.na(progcorrupt) & !is.na(solvecorrupt) & !is.na(corrupt) & !is.na(demonstrate_willingness) & !is.na(vote_invalid) & !is.na(conf_judge) & !is.na(conf_parties) & !is.na(conf_parl) & !is.na(vote_PJ))
cities14_withoutPJ_controls_T_full <- unique(subset(band14_withoutPJ_controls_full, band14_withoutPJ_controls_full$treat14==1)$ciudad) #cities in treatment
cities14_withoutPJ_controls_C_full <- unique(subset(band14_withoutPJ_controls_full, band14_withoutPJ_controls_full$treat14==0)$ciudad) #cities in control
cities14_withoutPJ_controls_full <- intersect(cities14_withoutPJ_controls_T_full,cities14_withoutPJ_controls_C_full) #cities with observations in both treatment and control
band14_withoutPJ_controls_full <- subset(band14_withoutPJ_controls_full, band14_withoutPJ_controls_full$ciudad %in% cities14_withoutPJ_controls_full) #observations from cities that are in both treatment and control
nrow(band14_withoutPJ_controls_full)

nrow(subset(band14_withoutPJ_controls_full,band14_withoutPJ_controls_full$treat14==1)) #observations in treatment
nrow(subset(band14_withoutPJ_controls_full,band14_withoutPJ_controls_full$treat14==0)) #observations in control


####Placebo tests
###with alternative cutoff dates:

set.seed(08112018) #the date on which the randomization occurred: 08-11-2018
sample(1:30,3,replace=F) #yielded 29, 23, 27 as randomly selected cutoff dates within the range of dates during which data collection occured

##for the first cutoff date (June 23, 2013):
d=23
#treatment (before vs. after randomly selected cutoff dates)
ARG$placebo7 <- ifelse(ARG$diareal<d & ARG$diareal>(d-8),0,NA)
ARG$placebo7 <- ifelse(ARG$diareal>d & ARG$diareal<(d+8),1,ARG$placebo7)

placebo_outcomes <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(progcorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$progcorrupt),1,0))
),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(solvecorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$solvecorrupt),1,0))
),
  c("corrupt",
    summary(lm(corrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(corrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$demonstrate_willingness),1,0))
),
  c("vote_null",
    summary(lm(vote_null ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_null ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_null),1,0))
),
  c("vote_not",
    summary(lm(vote_not ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_not ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_not),1,0))
),
  c("vote_invalid",
    summary(lm(vote_invalid ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_invalid ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_invalid),1,0))
),
  c("conf_judge",
    summary(lm(conf_judge ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_judge ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_judge),1,0))
),
  c("conf_parties",
    summary(lm(conf_parties ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parties ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_parties),1,0))
),
  c("conf_parl",
    summary(lm(conf_parl ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parl ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_parl),1,0))
))

colnames(placebo_outcomes) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

placebo_outcomes <- as.data.frame(placebo_outcomes)
placebo <- placebo_outcomes

colnames(placebo) <- c("Variable","Intercept","Estimate","SE","pvalue","ValidN")
placebo$Estimate <- as.numeric(as.character(placebo$Estimate))
placebo$SE <- as.numeric(as.character(placebo$SE))

placebo$Variable <- as.character(placebo$Variable)
placebo$Variable[placebo$Variable=="progcorrupt"] <- "Progress on\nstate corruption"
placebo$Variable[placebo$Variable=="solvecorrupt"] <- "State's ability to\nsolve corruption"
placebo$Variable[placebo$Variable=="corrupt"] <- "Prevalence of\ncorruption"
placebo$Variable[placebo$Variable=="vote_null"] <- "Vote null"
placebo$Variable[placebo$Variable=="vote_not"] <- "Not vote"
placebo$Variable[placebo$Variable=="vote_invalid"] <- "Invalid vote"
placebo$Variable[placebo$Variable=="conf_judge"] <- "Trust in judiciary"
placebo$Variable[placebo$Variable=="conf_parties"] <- "Trust in parties"
placebo$Variable[placebo$Variable=="conf_parl"] <- "Trust in congress"
placebo$Variable[placebo$Variable=="demonstrate_willingness"] <- "Willingness to\ndemonstrate"
placebo$Variable <- as.factor(placebo$Variable)
placebo$Variable <- factor(placebo$Variable,levels = c("Prevalence of\ncorruption","Progress on\nstate corruption","State's ability to\nsolve corruption","Political\ninterest","Willingness to\ndemonstrate","Vote null","Not vote", "Invalid vote", "Trust in judiciary", "Trust in parties", "Trust in congress"))

placebo_23 <- placebo


##for the second cutoff date (June 27, 2013):
d=27
#treatment (before vs. after randomly selected cutoff dates)
ARG$placebo7 <- ifelse(ARG$diareal<d & ARG$diareal>(d-8),0,NA)
ARG$placebo7 <- ifelse(ARG$diareal>d & ARG$diareal<(d+8),1,ARG$placebo7)

placebo_outcomes <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(progcorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(solvecorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(corrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_null ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_not ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_not),1,0))
  ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_invalid ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_invalid),1,0))
  ),
  c("conf_judge",
    summary(lm(conf_judge ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_judge ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parties ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parl ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_parl),1,0))
))

colnames(placebo_outcomes) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

placebo_outcomes <- as.data.frame(placebo_outcomes)
placebo <- placebo_outcomes

colnames(placebo) <- c("Variable","Intercept","Estimate","SE","pvalue","ValidN")
placebo$Estimate <- as.numeric(as.character(placebo$Estimate))
placebo$SE <- as.numeric(as.character(placebo$SE))

placebo$Variable <- as.character(placebo$Variable)
placebo$Variable[placebo$Variable=="progcorrupt"] <- "Progress on\nstate corruption"
placebo$Variable[placebo$Variable=="solvecorrupt"] <- "State's ability to\nsolve corruption"
placebo$Variable[placebo$Variable=="corrupt"] <- "Prevalence of\ncorruption"
placebo$Variable[placebo$Variable=="vote_null"] <- "Vote null"
placebo$Variable[placebo$Variable=="vote_not"] <- "Not vote"
placebo$Variable[placebo$Variable=="vote_invalid"] <- "Invalid vote"
placebo$Variable[placebo$Variable=="conf_judge"] <- "Trust in judiciary"
placebo$Variable[placebo$Variable=="conf_parties"] <- "Trust in parties"
placebo$Variable[placebo$Variable=="conf_parl"] <- "Trust in congress"
placebo$Variable[placebo$Variable=="demonstrate_willingness"] <- "Willingness to\ndemonstrate"
placebo$Variable <- as.factor(placebo$Variable)
placebo$Variable <- factor(placebo$Variable,levels = c("Prevalence of\ncorruption","Progress on\nstate corruption","State's ability to\nsolve corruption","Political\ninterest","Willingness to\ndemonstrate","Vote null","Not vote", "Invalid vote", "Trust in judiciary", "Trust in parties", "Trust in congress"))

placebo_27 <- placebo


##for the third cutoff date (June 29, 2013):
d=29
#treatment (before vs. after randomly selected cutoff dates)
ARG$placebo7 <- ifelse(ARG$diareal<d & ARG$diareal>(d-8),0,NA)
ARG$placebo7 <- ifelse(ARG$diareal>d & ARG$diareal<(d+8),1,ARG$placebo7)

placebo_outcomes <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(progcorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(solvecorrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(corrupt ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$corrupt),1,0))
  ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_null ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_not ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_invalid ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_judge ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parties ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parl ~ placebo7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo7==0|ARG$placebo7==1)$conf_parl),1,0))
    ))

colnames(placebo_outcomes) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

placebo_outcomes <- as.data.frame(placebo_outcomes)
placebo <- placebo_outcomes

colnames(placebo) <- c("Variable","Intercept","Estimate","SE","pvalue","ValidN")
placebo$Estimate <- as.numeric(as.character(placebo$Estimate))
placebo$SE <- as.numeric(as.character(placebo$SE))

placebo$Variable <- as.character(placebo$Variable)
placebo$Variable[placebo$Variable=="progcorrupt"] <- "Progress on\nstate corruption"
placebo$Variable[placebo$Variable=="solvecorrupt"] <- "State's ability to\nsolve corruption"
placebo$Variable[placebo$Variable=="corrupt"] <- "Prevalence of\ncorruption"
placebo$Variable[placebo$Variable=="vote_null"] <- "Vote null"
placebo$Variable[placebo$Variable=="vote_not"] <- "Not vote"
placebo$Variable[placebo$Variable=="vote_invalid"] <- "Invalid vote"
placebo$Variable[placebo$Variable=="conf_judge"] <- "Trust in judiciary"
placebo$Variable[placebo$Variable=="conf_parties"] <- "Trust in parties"
placebo$Variable[placebo$Variable=="conf_parl"] <- "Trust in congress"
placebo$Variable[placebo$Variable=="demonstrate_willingness"] <- "Willingness to\ndemonstrate"
placebo$Variable <- as.factor(placebo$Variable)
placebo$Variable <- factor(placebo$Variable,levels = c("Prevalence of\ncorruption","Progress on\nstate corruption","State's ability to\nsolve corruption","Political\ninterest","Willingness to\ndemonstrate","Vote null","Not vote", "Invalid vote", "Trust in judiciary", "Trust in parties", "Trust in congress"))

placebo_29 <- placebo

##to merge the results from the three placebo tests:
placebo_23$date <- "June 23"
placebo_27$date <- "June 27"
placebo_29$date <- "June 29"

placebo <- rbind(placebo_23,placebo_27,placebo_29)

#Figure A7:
ggplot(placebo_23, aes(y=Estimate,x=Variable)) +
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("\nTreatment effect")+
  xlab("")+
  theme(axis.text.x = element_text(angle = 90,vjust=0.5,hjust=0.9))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-1.5,-1.25,-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1,1.25,1.5), limits=c(-1.5,1.5))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.95)/2)), ymin=Estimate - (SE*-qnorm((1-0.95)/2))), width=.1, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("FigureA7.pdf", width = 12, height = 7)

#Figure A8:
ggplot(placebo_27, aes(y=Estimate,x=Variable)) +
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("\nTreatment effect")+
  xlab("")+
  theme(axis.text.x = element_text(angle = 90,vjust=0.5,hjust=0.9))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-1.5,-1.25,-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1,1.25,1.5), limits=c(-1.5,1.5))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.95)/2)), ymin=Estimate - (SE*-qnorm((1-0.95)/2))), width=.1, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("FigureA8.pdf", width = 12, height = 7)

#Figure A9:
ggplot(placebo_29, aes(y=Estimate,x=Variable)) +
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("\nTreatment effect")+
  xlab("")+
  theme(axis.text.x = element_text(angle = 90,vjust=0.5,hjust=0.9))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-1.5,-1.25,-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1,1.25,1.5), limits=c(-1.5,1.5))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.95)/2)), ymin=Estimate - (SE*-qnorm((1-0.95)/2))), width=.1, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("FigureA9.pdf", width = 12, height = 7)


## Placebo test for median of control group (June 6):
## Figure A10:
d=6
#treatment (before vs. after median of control group)
ARG$placebo <- ifelse(ARG$diareal<d,0,NA)
ARG$placebo <- ifelse(ARG$diareal>d & ARG$diareal<13,1,ARG$placebo)

placebo_outcomes <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(progcorrupt ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$progcorrupt),1,0))),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(solvecorrupt ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$solvecorrupt),1,0))),
  c("corrupt",
    summary(lm(corrupt ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(corrupt ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$corrupt),1,0))),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$demonstrate_willingness),1,0))),
  c("vote_null",
    summary(lm(vote_null ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_null ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$vote_null),1,0))),
  c("vote_not",
    summary(lm(vote_not ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_not ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$vote_not),1,0))),
  c("vote_invalid",
    summary(lm(vote_invalid ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(vote_invalid ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$vote_invalid),1,0))),
  c("conf_judge",
    summary(lm(conf_judge ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_judge ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$conf_judge),1,0))),
  c("conf_parties",
    summary(lm(conf_parties ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parties ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$conf_parties),1,0))),
  c("conf_parl",
    summary(lm(conf_parl ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[1,1],
    summary(lm(conf_parl ~ placebo + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0|ARG$placebo==1)$conf_parl),1,0)))
)

colnames(placebo_outcomes) <- c("Variable","Intercept","Estimate","SE","pvalue","ValidN")

placebo_outcomes <- as.data.frame(placebo_outcomes)
placebo <- placebo_outcomes

placebo$Estimate <- as.numeric(as.character(placebo$Estimate))
placebo$SE <- as.numeric(as.character(placebo$SE))

placebo$Variable <- as.character(placebo$Variable)
placebo$Variable[placebo$Variable=="progcorrupt"] <- "Progress on\nstate corruption"
placebo$Variable[placebo$Variable=="solvecorrupt"] <- "State's ability to\nsolve corruption"
placebo$Variable[placebo$Variable=="corrupt"] <- "Prevalence of\ncorruption"
placebo$Variable[placebo$Variable=="vote_null"] <- "Vote null"
placebo$Variable[placebo$Variable=="vote_not"] <- "Not vote"
placebo$Variable[placebo$Variable=="vote_invalid"] <- "Invalid vote"
placebo$Variable[placebo$Variable=="conf_judge"] <- "Trust in judiciary"
placebo$Variable[placebo$Variable=="conf_parties"] <- "Trust in parties"
placebo$Variable[placebo$Variable=="conf_parl"] <- "Trust in congress"
placebo$Variable[placebo$Variable=="demonstrate_willingness"] <- "Willingness to\ndemonstrate"
placebo$Variable <- as.factor(placebo$Variable)
placebo$Variable <- factor(placebo$Variable,levels = c("Prevalence of\ncorruption","Progress on\nstate corruption","State's ability to\nsolve corruption","Political\ninterest","Willingness to\ndemonstrate","Vote null","Not vote", "Invalid vote", "Trust in judiciary", "Trust in parties", "Trust in congress"))

placebo_6 <- placebo

placebo_6$date <- "June 6"

ggplot(placebo_6, aes(y=Estimate,x=Variable)) +
  ggtitle("")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("\nTreatment effect")+
  xlab("")+
  theme(axis.text.x = element_text(angle = 90,vjust=0.5,hjust=0.9))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-1.5,-1.25,-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1,1.25,1.5), limits=c(-1.5,1.5))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Estimate + (SE*-qnorm((1-0.95)/2)), ymin=Estimate - (SE*-qnorm((1-0.95)/2))), width=.1, position=position_dodge(.9),stat="identity",size=0.8)
ggsave("FigureA10.pdf", width = 12, height = 7)


##Checking for time trends in control group:

control_analytic <- subset(band14_controls_full,band14_controls_full$treat14==0) #observations in control

timetrend_control_analytic <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(progcorrupt ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$progcorrupt),1,0))),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(solvecorrupt ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$solvecorrupt),1,0))),
  c("corrupt",
    summary(lm(corrupt ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(corrupt ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$corrupt),1,0))),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$demonstrate_willingness),1,0))),
  c("vote_null",
    summary(lm(vote_null ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(vote_null ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$vote_null),1,0))),
  c("vote_not",
    summary(lm(vote_not ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(vote_not ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$vote_not),1,0))),
  c("vote_invalid",
    summary(lm(vote_invalid ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(vote_invalid ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$vote_invalid),1,0))),
  c("conf_judge",
    summary(lm(conf_judge ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(conf_judge ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$conf_judge),1,0))),
  c("conf_parties",
    summary(lm(conf_parties ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(conf_parties ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$conf_parties),1,0))),
  c("conf_parl",
    summary(lm(conf_parl ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[1,1],
    summary(lm(conf_parl ~ diareal + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=control_analytic))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG,ARG$placebo==0 | placebo==1)$conf_parl),1,0)))
)

colnames(timetrend_control_analytic) <- c("Variable","Intercept","Estimate","SE","pvalue","ValidN")

timetrend_control_analytic <- as.data.frame(timetrend_control_analytic)
timetrend_control_analytic


####Het. effects:

###by gender:
###Table A14:

##men:
men <- subset(ARG, ARG$male==1)

outcomes_men <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=men))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(men,men$treat7==0|men$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_men) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_men <- outcomes_men[,c(1,3,4:6)]
het_men[,2] <- round(as.numeric(het_men[,2]),3)
het_men[,3] <- round(as.numeric(het_men[,3]),3)
het_men[,4] <- round(as.numeric(het_men[,4]),3) 

het_men <- as.data.frame(het_men[c(1:4,7:10),])

het_men[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_men) <- c("Variable","Effect","SE","p Value", "N")

het_men


##female:
female <- subset(ARG, ARG$male==0)

outcomes_female <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$solvecorrupt),1,0))
  ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$corrupt),1,0))
  ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=female))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(female,female$treat7==0|female$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_female) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_women <- outcomes_female[,c(1,3,4:6)]
het_women[,2] <- round(as.numeric(het_women[,2]),3)
het_women[,3] <- round(as.numeric(het_women[,3]),3)
het_women[,4] <- round(as.numeric(het_women[,4]),3) 

het_women <- as.data.frame(het_women[c(1:4,7:10),])

het_women[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_women) <- c("Variable","Effect","SE","p Value", "N")

het_women


##interact_gender:
valid_gender <- subset(ARG, !is.na(male))

outcomes_interact_gender <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$progcorrupt),1,0))
),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$solvecorrupt),1,0))
  ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 * male + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_gender))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_gender,valid_gender$treat7==0|valid_gender$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_interact_gender) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_interact_gender <- outcomes_interact_gender[,c(1,3,4:6)]
het_interact_gender[,2] <- round(as.numeric(het_interact_gender[,2]),3)
het_interact_gender[,3] <- round(as.numeric(het_interact_gender[,3]),3)
het_interact_gender[,4] <- round(as.numeric(het_interact_gender[,4]),3) 

het_interact_gender <- as.data.frame(het_interact_gender[c(1:4,7:10),])

het_interact_gender[,1] <-  c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_interact_gender) <- c("Variable","Effect","SE","p Value", "N")

het_interact_gender

##combine the output for the different subgroup analyses & interaction term:
ARG_het_men <- as.data.frame(cbind(rep(NA,2*nrow(het_women)),rep(NA,2*nrow(het_women)),rep(NA,2*nrow(het_women)),rep(NA,2*nrow(het_women))))

ARG_het_men[1,1] <- het_women[1,1]
ARG_het_men[2,1] <- ""
ARG_het_men[3,1] <- het_women[2,1]
ARG_het_men[4,1] <- ""
ARG_het_men[5,1] <- het_women[3,1]
ARG_het_men[6,1] <- ""
ARG_het_men[7,1] <- het_women[4,1]
ARG_het_men[8,1] <- ""
ARG_het_men[9,1] <- het_women[5,1]
ARG_het_men[10,1] <- ""
ARG_het_men[11,1] <- het_women[6,1]
ARG_het_men[12,1] <- ""
ARG_het_men[13,1] <- het_women[7,1]
ARG_het_men[14,1] <- ""
ARG_het_men[15,1] <- het_women[8,1]
ARG_het_men[16,1] <- ""
ARG_het_men[17,1] <- "Sample"

het_women[,2] <- as.numeric(as.character(het_women[,2]))
het_women[,3] <- as.numeric(as.character(het_women[,3]))
het_women[,4] <- as.numeric(as.character(het_women[,4]))

ARG_het_men[17,2] <- "Women"
ARG_het_men[1,2] <- ifelse(het_women[1,4]<0.1,paste0(het_women[1,2],"*"),het_women[1,2])
ARG_het_men[1,2] <- ifelse(het_women[1,4]<0.05,paste0(het_women[1,2],"**"),ARG_het_men[1,2])
ARG_het_men[1,2] <- ifelse(het_women[1,4]<0.01,paste0(het_women[1,2],"***"),ARG_het_men[1,2])

ARG_het_men[3,2] <- ifelse(het_women[2,4]<0.1,paste0(het_women[2,2],"*"),het_women[2,2])
ARG_het_men[3,2] <- ifelse(het_women[2,4]<0.05,paste0(het_women[2,2],"**"),ARG_het_men[3,2])
ARG_het_men[3,2] <- ifelse(het_women[2,4]<0.01,paste0(het_women[2,2],"***"),ARG_het_men[3,2])

ARG_het_men[5,2] <- ifelse(het_women[3,4]<0.1,paste0(het_women[3,2],"*"),het_women[3,2])
ARG_het_men[5,2] <- ifelse(het_women[3,4]<0.05,paste0(het_women[3,2],"**"),ARG_het_men[5,2])
ARG_het_men[5,2] <- ifelse(het_women[3,4]<0.01,paste0(het_women[3,2],"***"),ARG_het_men[5,2])

ARG_het_men[7,2] <- ifelse(het_women[4,4]<0.1,paste0(het_women[4,2],"*"),het_women[4,2])
ARG_het_men[7,2] <- ifelse(het_women[4,4]<0.05,paste0(het_women[4,2],"**"),ARG_het_men[7,2])
ARG_het_men[7,2] <- ifelse(het_women[4,4]<0.01,paste0(het_women[4,2],"***"),ARG_het_men[7,2])

ARG_het_men[9,2] <- ifelse(het_women[5,4]<0.1,paste0(het_women[5,2],"*"),het_women[5,2])
ARG_het_men[9,2] <- ifelse(het_women[5,4]<0.05,paste0(het_women[5,2],"**"),ARG_het_men[9,2])
ARG_het_men[9,2] <- ifelse(het_women[5,4]<0.01,paste0(het_women[5,2],"***"),ARG_het_men[9,2])

ARG_het_men[11,2] <- ifelse(het_women[6,4]<0.1,paste0(het_women[6,2],"*"),het_women[6,2])
ARG_het_men[11,2] <- ifelse(het_women[6,4]<0.05,paste0(het_women[6,2],"**"),ARG_het_men[11,2])
ARG_het_men[11,2] <- ifelse(het_women[6,4]<0.01,paste0(het_women[6,2],"***"),ARG_het_men[11,2])

ARG_het_men[13,2] <- ifelse(het_women[7,4]<0.1,paste0(het_women[7,2],"*"),het_women[7,2])
ARG_het_men[13,2] <- ifelse(het_women[7,4]<0.05,paste0(het_women[7,2],"**"),ARG_het_men[13,2])
ARG_het_men[13,2] <- ifelse(het_women[7,4]<0.01,paste0(het_women[7,2],"***"),ARG_het_men[13,2])

ARG_het_men[15,2] <- ifelse(het_women[8,4]<0.1,paste0(het_women[8,2],"*"),het_women[8,2])
ARG_het_men[15,2] <- ifelse(het_women[8,4]<0.05,paste0(het_women[8,2],"**"),ARG_het_men[15,2])
ARG_het_men[15,2] <- ifelse(het_women[8,4]<0.01,paste0(het_women[8,2],"***"),ARG_het_men[15,2])

ARG_het_men[2,2] <- paste0("(",het_women[1,3],")")
ARG_het_men[4,2] <- paste0("(",het_women[2,3],")")
ARG_het_men[6,2] <- paste0("(",het_women[3,3],")")
ARG_het_men[8,2] <- paste0("(",het_women[4,3],")")
ARG_het_men[10,2] <- paste0("(",het_women[5,3],")")
ARG_het_men[12,2] <- paste0("(",het_women[6,3],")")
ARG_het_men[14,2] <- paste0("(",het_women[7,3],")")
ARG_het_men[16,2] <- paste0("(",het_women[8,3],")")

het_men[,2] <- as.numeric(as.character(het_men[,2]))
het_men[,3] <- as.numeric(as.character(het_men[,3]))
het_men[,4] <- as.numeric(as.character(het_men[,4]))

ARG_het_men[17,3] <- "Men"
ARG_het_men[1,3] <- ifelse(het_men[1,4]<0.1,paste0(het_men[1,2],"*"),het_men[1,2])
ARG_het_men[1,3] <- ifelse(het_men[1,4]<0.05,paste0(het_men[1,2],"**"),ARG_het_men[1,3])
ARG_het_men[1,3] <- ifelse(het_men[1,4]<0.01,paste0(het_men[1,2],"***"),ARG_het_men[1,3])

ARG_het_men[3,3] <- ifelse(het_men[2,4]<0.1,paste0(het_men[2,2],"*"),het_men[2,2])
ARG_het_men[3,3] <- ifelse(het_men[2,4]<0.05,paste0(het_men[2,2],"**"),ARG_het_men[3,3])
ARG_het_men[3,3] <- ifelse(het_men[2,4]<0.01,paste0(het_men[2,2],"***"),ARG_het_men[3,3])

ARG_het_men[5,3] <- ifelse(het_men[3,4]<0.1,paste0(het_men[3,2],"*"),het_men[3,2])
ARG_het_men[5,3] <- ifelse(het_men[3,4]<0.05,paste0(het_men[3,2],"**"),ARG_het_men[5,3])
ARG_het_men[5,3] <- ifelse(het_men[3,4]<0.01,paste0(het_men[3,2],"***"),ARG_het_men[5,3])

ARG_het_men[7,3] <- ifelse(het_men[4,4]<0.1,paste0(het_men[4,2],"*"),het_men[4,2])
ARG_het_men[7,3] <- ifelse(het_men[4,4]<0.05,paste0(het_men[4,2],"**"),ARG_het_men[7,3])
ARG_het_men[7,3] <- ifelse(het_men[4,4]<0.01,paste0(het_men[4,2],"***"),ARG_het_men[7,3])

ARG_het_men[9,3] <- ifelse(het_men[5,4]<0.1,paste0(het_men[5,2],"*"),het_men[5,2])
ARG_het_men[9,3] <- ifelse(het_men[5,4]<0.05,paste0(het_men[5,2],"**"),ARG_het_men[9,3])
ARG_het_men[9,3] <- ifelse(het_men[5,4]<0.01,paste0(het_men[5,2],"***"),ARG_het_men[9,3])

ARG_het_men[11,3] <- ifelse(het_men[6,4]<0.1,paste0(het_men[6,2],"*"),het_men[6,2])
ARG_het_men[11,3] <- ifelse(het_men[6,4]<0.05,paste0(het_men[6,2],"**"),ARG_het_men[11,3])
ARG_het_men[11,3] <- ifelse(het_men[6,4]<0.01,paste0(het_men[6,2],"***"),ARG_het_men[11,3])

ARG_het_men[13,3] <- ifelse(het_men[7,4]<0.1,paste0(het_men[7,2],"*"),het_men[7,2])
ARG_het_men[13,3] <- ifelse(het_men[7,4]<0.05,paste0(het_men[7,2],"**"),ARG_het_men[13,3])
ARG_het_men[13,3] <- ifelse(het_men[7,4]<0.01,paste0(het_men[7,2],"***"),ARG_het_men[13,3])

ARG_het_men[15,3] <- ifelse(het_men[8,4]<0.1,paste0(het_men[8,2],"*"),het_men[8,2])
ARG_het_men[15,3] <- ifelse(het_men[8,4]<0.05,paste0(het_men[8,2],"**"),ARG_het_men[15,3])
ARG_het_men[15,3] <- ifelse(het_men[8,4]<0.01,paste0(het_men[8,2],"***"),ARG_het_men[15,3])

ARG_het_men[2,3] <- paste0("(",het_men[1,3],")")
ARG_het_men[4,3] <- paste0("(",het_men[2,3],")")
ARG_het_men[6,3] <- paste0("(",het_men[3,3],")")
ARG_het_men[8,3] <- paste0("(",het_men[4,3],")")
ARG_het_men[10,3] <- paste0("(",het_men[5,3],")")
ARG_het_men[12,3] <- paste0("(",het_men[6,3],")")
ARG_het_men[14,3] <- paste0("(",het_men[7,3],")")
ARG_het_men[16,3] <- paste0("(",het_men[8,3],")")

het_interact_gender[,2] <- as.numeric(as.character(het_interact_gender[,2]))
het_interact_gender[,3] <- as.numeric(as.character(het_interact_gender[,3]))
het_interact_gender[,4] <- as.numeric(as.character(het_interact_gender[,4]))

ARG_het_men[17,4] <- "Interaction Term"
ARG_het_men[1,4] <- ifelse(het_interact_gender[1,4]<0.1,paste0(het_interact_gender[1,2],"*"),het_interact_gender[1,2])
ARG_het_men[1,4] <- ifelse(het_interact_gender[1,4]<0.05,paste0(het_interact_gender[1,2],"**"),ARG_het_men[1,4])
ARG_het_men[1,4] <- ifelse(het_interact_gender[1,4]<0.01,paste0(het_interact_gender[1,2],"***"),ARG_het_men[1,4])

ARG_het_men[3,4] <- ifelse(het_interact_gender[2,4]<0.1,paste0(het_interact_gender[2,2],"*"),het_interact_gender[2,2])
ARG_het_men[3,4] <- ifelse(het_interact_gender[2,4]<0.05,paste0(het_interact_gender[2,2],"**"),ARG_het_men[3,4])
ARG_het_men[3,4] <- ifelse(het_interact_gender[2,4]<0.01,paste0(het_interact_gender[2,2],"***"),ARG_het_men[3,4])

ARG_het_men[5,4] <- ifelse(het_interact_gender[3,4]<0.1,paste0(het_interact_gender[3,2],"*"),het_interact_gender[3,2])
ARG_het_men[5,4] <- ifelse(het_interact_gender[3,4]<0.05,paste0(het_interact_gender[3,2],"**"),ARG_het_men[5,4])
ARG_het_men[5,4] <- ifelse(het_interact_gender[3,4]<0.01,paste0(het_interact_gender[3,2],"***"),ARG_het_men[5,4])

ARG_het_men[7,4] <- ifelse(het_interact_gender[4,4]<0.1,paste0(het_interact_gender[4,2],"*"),het_interact_gender[4,2])
ARG_het_men[7,4] <- ifelse(het_interact_gender[4,4]<0.05,paste0(het_interact_gender[4,2],"**"),ARG_het_men[7,4])
ARG_het_men[7,4] <- ifelse(het_interact_gender[4,4]<0.01,paste0(het_interact_gender[4,2],"***"),ARG_het_men[7,4])

ARG_het_men[9,4] <- ifelse(het_interact_gender[5,4]<0.1,paste0(het_interact_gender[5,2],"*"),het_interact_gender[5,2])
ARG_het_men[9,4] <- ifelse(het_interact_gender[5,4]<0.05,paste0(het_interact_gender[5,2],"**"),ARG_het_men[9,4])
ARG_het_men[9,4] <- ifelse(het_interact_gender[5,4]<0.01,paste0(het_interact_gender[5,2],"***"),ARG_het_men[9,4])

ARG_het_men[11,4] <- ifelse(het_interact_gender[6,4]<0.1,paste0(het_interact_gender[6,2],"*"),het_interact_gender[6,2])
ARG_het_men[11,4] <- ifelse(het_interact_gender[6,4]<0.05,paste0(het_interact_gender[6,2],"**"),ARG_het_men[11,4])
ARG_het_men[11,4] <- ifelse(het_interact_gender[6,4]<0.01,paste0(het_interact_gender[6,2],"***"),ARG_het_men[11,4])

ARG_het_men[13,4] <- ifelse(het_interact_gender[7,4]<0.1,paste0(het_interact_gender[7,2],"*"),het_interact_gender[7,2])
ARG_het_men[13,4] <- ifelse(het_interact_gender[7,4]<0.05,paste0(het_interact_gender[7,2],"**"),ARG_het_men[13,4])
ARG_het_men[13,4] <- ifelse(het_interact_gender[7,4]<0.01,paste0(het_interact_gender[7,2],"***"),ARG_het_men[13,4])

ARG_het_men[15,4] <- ifelse(het_interact_gender[8,4]<0.1,paste0(het_interact_gender[8,2],"*"),het_interact_gender[8,2])
ARG_het_men[15,4] <- ifelse(het_interact_gender[8,4]<0.05,paste0(het_interact_gender[8,2],"**"),ARG_het_men[15,4])
ARG_het_men[15,4] <- ifelse(het_interact_gender[8,4]<0.01,paste0(het_interact_gender[8,2],"***"),ARG_het_men[15,4])

ARG_het_men[2,4] <- paste0("(",het_interact_gender[1,3],")")
ARG_het_men[4,4] <- paste0("(",het_interact_gender[2,3],")")
ARG_het_men[6,4] <- paste0("(",het_interact_gender[3,3],")")
ARG_het_men[8,4] <- paste0("(",het_interact_gender[4,3],")")
ARG_het_men[10,4] <- paste0("(",het_interact_gender[5,3],")")
ARG_het_men[12,4] <- paste0("(",het_interact_gender[6,3],")")
ARG_het_men[14,4] <- paste0("(",het_interact_gender[7,3],")")
ARG_het_men[16,4] <- paste0("(",het_interact_gender[8,3],")")

ARG_het_men

#Table A14:
stargazer(as.matrix(ARG_het_men), rownames=F, out="TableA14.tex")


###by region:
###Table A13:

##conurbano:
conurbano <- subset(ARG, ARG$reg==32001 | ARG$reg==32301)
ARG$conurbano <- ifelse(ARG$reg==32001 | ARG$reg==32301, 1, 0)

outcomes_conurbano <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=conurbano))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(conurbano,treat7==0|treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_conurbano) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_conurbano <- outcomes_conurbano[,c(1,3,4:6)]
het_conurbano[,2] <- round(as.numeric(het_conurbano[,2]),3)
het_conurbano[,3] <- round(as.numeric(het_conurbano[,3]),3)
het_conurbano[,4] <- round(as.numeric(het_conurbano[,4]),3) 

het_conurbano <- as.data.frame(het_conurbano[c(1:4,7:10),])

het_conurbano[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_conurbano) <- c("Variable","Effect","SE","p Value", "N")

het_conurbano


##other_provinces:
other_provinces <- subset(ARG, ARG$reg!=32001 & ARG$reg!=32301)

outcomes_other_provinces <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=other_provinces))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(other_provinces,other_provinces$treat7==0|other_provinces$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_other_provinces) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_other_provinces <- outcomes_other_provinces[,c(1,3,4:6)]
het_other_provinces[,2] <- round(as.numeric(het_other_provinces[,2]),3)
het_other_provinces[,3] <- round(as.numeric(het_other_provinces[,3]),3)
het_other_provinces[,4] <- round(as.numeric(het_other_provinces[,4]),3) 

het_other_provinces <- as.data.frame(het_other_provinces[c(1:4,7:10),])

het_other_provinces[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_other_provinces) <- c("Variable","Effect","SE","p Value", "N")

het_other_provinces


##interact_region:
valid_region <- subset(ARG, !is.na(conurbano))

outcomes_interact_region <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$progcorrupt),1,0))
),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$solvecorrupt),1,0))
  ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$corrupt),1,0))
  ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 * conurbano + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_region))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_region,valid_region$treat7==0|valid_region$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_interact_region) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_interact_region <- outcomes_interact_region[,c(1,3,4:6)]
het_interact_region[,2] <- round(as.numeric(het_interact_region[,2]),3)
het_interact_region[,3] <- round(as.numeric(het_interact_region[,3]),3)
het_interact_region[,4] <- round(as.numeric(het_interact_region[,4]),3) 

het_interact_region <- as.data.frame(het_interact_region[c(1:4,7:10),])

het_interact_region[,1] <-  c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

het_interact_region

##combine the output for the different subgroup analyses & interaction term:
ARG_het_region <- as.data.frame(cbind(rep(NA,2*nrow(het_other_provinces)),rep(NA,2*nrow(het_other_provinces)),rep(NA,2*nrow(het_other_provinces)),rep(NA,2*nrow(het_other_provinces))))

ARG_het_region[1,1] <- het_other_provinces[1,1]
ARG_het_region[2,1] <- ""
ARG_het_region[3,1] <- het_other_provinces[2,1]
ARG_het_region[4,1] <- ""
ARG_het_region[5,1] <- het_other_provinces[3,1]
ARG_het_region[6,1] <- ""
ARG_het_region[7,1] <- het_other_provinces[4,1]
ARG_het_region[8,1] <- ""
ARG_het_region[9,1] <- het_other_provinces[5,1]
ARG_het_region[10,1] <- ""
ARG_het_region[11,1] <- het_other_provinces[6,1]
ARG_het_region[12,1] <- ""
ARG_het_region[13,1] <- het_other_provinces[7,1]
ARG_het_region[14,1] <- ""
ARG_het_region[15,1] <- het_other_provinces[8,1]
ARG_het_region[16,1] <- ""
ARG_het_region[17,1] <- "Sample"

het_other_provinces[,2] <- as.numeric(as.character(het_other_provinces[,2]))
het_other_provinces[,3] <- as.numeric(as.character(het_other_provinces[,3]))
het_other_provinces[,4] <- as.numeric(as.character(het_other_provinces[,4]))

ARG_het_region[17,2] <- "Other Provinces"
ARG_het_region[1,2] <- ifelse(het_other_provinces[1,4]<0.1,paste0(het_other_provinces[1,2],"*"),het_other_provinces[1,2])
ARG_het_region[1,2] <- ifelse(het_other_provinces[1,4]<0.05,paste0(het_other_provinces[1,2],"**"),ARG_het_region[1,2])
ARG_het_region[1,2] <- ifelse(het_other_provinces[1,4]<0.01,paste0(het_other_provinces[1,2],"***"),ARG_het_region[1,2])

ARG_het_region[3,2] <- ifelse(het_other_provinces[2,4]<0.1,paste0(het_other_provinces[2,2],"*"),het_other_provinces[2,2])
ARG_het_region[3,2] <- ifelse(het_other_provinces[2,4]<0.05,paste0(het_other_provinces[2,2],"**"),ARG_het_region[3,2])
ARG_het_region[3,2] <- ifelse(het_other_provinces[2,4]<0.01,paste0(het_other_provinces[2,2],"***"),ARG_het_region[3,2])

ARG_het_region[5,2] <- ifelse(het_other_provinces[3,4]<0.1,paste0(het_other_provinces[3,2],"*"),het_other_provinces[3,2])
ARG_het_region[5,2] <- ifelse(het_other_provinces[3,4]<0.05,paste0(het_other_provinces[3,2],"**"),ARG_het_region[5,2])
ARG_het_region[5,2] <- ifelse(het_other_provinces[3,4]<0.01,paste0(het_other_provinces[3,2],"***"),ARG_het_region[5,2])

ARG_het_region[7,2] <- ifelse(het_other_provinces[4,4]<0.1,paste0(het_other_provinces[4,2],"*"),het_other_provinces[4,2])
ARG_het_region[7,2] <- ifelse(het_other_provinces[4,4]<0.05,paste0(het_other_provinces[4,2],"**"),ARG_het_region[7,2])
ARG_het_region[7,2] <- ifelse(het_other_provinces[4,4]<0.01,paste0(het_other_provinces[4,2],"***"),ARG_het_region[7,2])

ARG_het_region[9,2] <- ifelse(het_other_provinces[5,4]<0.1,paste0(het_other_provinces[5,2],"*"),het_other_provinces[5,2])
ARG_het_region[9,2] <- ifelse(het_other_provinces[5,4]<0.05,paste0(het_other_provinces[5,2],"**"),ARG_het_region[9,2])
ARG_het_region[9,2] <- ifelse(het_other_provinces[5,4]<0.01,paste0(het_other_provinces[5,2],"***"),ARG_het_region[9,2])

ARG_het_region[11,2] <- ifelse(het_other_provinces[6,4]<0.1,paste0(het_other_provinces[6,2],"*"),het_other_provinces[6,2])
ARG_het_region[11,2] <- ifelse(het_other_provinces[6,4]<0.05,paste0(het_other_provinces[6,2],"**"),ARG_het_region[11,2])
ARG_het_region[11,2] <- ifelse(het_other_provinces[6,4]<0.01,paste0(het_other_provinces[6,2],"***"),ARG_het_region[11,2])

ARG_het_region[13,2] <- ifelse(het_other_provinces[7,4]<0.1,paste0(het_other_provinces[7,2],"*"),het_other_provinces[7,2])
ARG_het_region[13,2] <- ifelse(het_other_provinces[7,4]<0.05,paste0(het_other_provinces[7,2],"**"),ARG_het_region[13,2])
ARG_het_region[13,2] <- ifelse(het_other_provinces[7,4]<0.01,paste0(het_other_provinces[7,2],"***"),ARG_het_region[13,2])

ARG_het_region[15,2] <- ifelse(het_other_provinces[8,4]<0.1,paste0(het_other_provinces[8,2],"*"),het_other_provinces[8,2])
ARG_het_region[15,2] <- ifelse(het_other_provinces[8,4]<0.05,paste0(het_other_provinces[8,2],"**"),ARG_het_region[15,2])
ARG_het_region[15,2] <- ifelse(het_other_provinces[8,4]<0.01,paste0(het_other_provinces[8,2],"***"),ARG_het_region[15,2])

ARG_het_region[2,2] <- paste0("(",het_other_provinces[1,3],")")
ARG_het_region[4,2] <- paste0("(",het_other_provinces[2,3],")")
ARG_het_region[6,2] <- paste0("(",het_other_provinces[3,3],")")
ARG_het_region[8,2] <- paste0("(",het_other_provinces[4,3],")")
ARG_het_region[10,2] <- paste0("(",het_other_provinces[5,3],")")
ARG_het_region[12,2] <- paste0("(",het_other_provinces[6,3],")")
ARG_het_region[14,2] <- paste0("(",het_other_provinces[7,3],")")
ARG_het_region[16,2] <- paste0("(",het_other_provinces[8,3],")")

het_conurbano[,2] <- as.numeric(as.character(het_conurbano[,2]))
het_conurbano[,3] <- as.numeric(as.character(het_conurbano[,3]))
het_conurbano[,4] <- as.numeric(as.character(het_conurbano[,4]))

ARG_het_region[17,3] <- "Conurbano"
ARG_het_region[1,3] <- ifelse(het_conurbano[1,4]<0.1,paste0(het_conurbano[1,2],"*"),het_conurbano[1,2])
ARG_het_region[1,3] <- ifelse(het_conurbano[1,4]<0.05,paste0(het_conurbano[1,2],"**"),ARG_het_region[1,3])
ARG_het_region[1,3] <- ifelse(het_conurbano[1,4]<0.01,paste0(het_conurbano[1,2],"***"),ARG_het_region[1,3])

ARG_het_region[3,3] <- ifelse(het_conurbano[2,4]<0.1,paste0(het_conurbano[2,2],"*"),het_conurbano[2,2])
ARG_het_region[3,3] <- ifelse(het_conurbano[2,4]<0.05,paste0(het_conurbano[2,2],"**"),ARG_het_region[3,3])
ARG_het_region[3,3] <- ifelse(het_conurbano[2,4]<0.01,paste0(het_conurbano[2,2],"***"),ARG_het_region[3,3])

ARG_het_region[5,3] <- ifelse(het_conurbano[3,4]<0.1,paste0(het_conurbano[3,2],"*"),het_conurbano[3,2])
ARG_het_region[5,3] <- ifelse(het_conurbano[3,4]<0.05,paste0(het_conurbano[3,2],"**"),ARG_het_region[5,3])
ARG_het_region[5,3] <- ifelse(het_conurbano[3,4]<0.01,paste0(het_conurbano[3,2],"***"),ARG_het_region[5,3])

ARG_het_region[7,3] <- ifelse(het_conurbano[4,4]<0.1,paste0(het_conurbano[4,2],"*"),het_conurbano[4,2])
ARG_het_region[7,3] <- ifelse(het_conurbano[4,4]<0.05,paste0(het_conurbano[4,2],"**"),ARG_het_region[7,3])
ARG_het_region[7,3] <- ifelse(het_conurbano[4,4]<0.01,paste0(het_conurbano[4,2],"***"),ARG_het_region[7,3])

ARG_het_region[9,3] <- ifelse(het_conurbano[5,4]<0.1,paste0(het_conurbano[5,2],"*"),het_conurbano[5,2])
ARG_het_region[9,3] <- ifelse(het_conurbano[5,4]<0.05,paste0(het_conurbano[5,2],"**"),ARG_het_region[9,3])
ARG_het_region[9,3] <- ifelse(het_conurbano[5,4]<0.01,paste0(het_conurbano[5,2],"***"),ARG_het_region[9,3])

ARG_het_region[11,3] <- ifelse(het_conurbano[6,4]<0.1,paste0(het_conurbano[6,2],"*"),het_conurbano[6,2])
ARG_het_region[11,3] <- ifelse(het_conurbano[6,4]<0.05,paste0(het_conurbano[6,2],"**"),ARG_het_region[11,3])
ARG_het_region[11,3] <- ifelse(het_conurbano[6,4]<0.01,paste0(het_conurbano[6,2],"***"),ARG_het_region[11,3])

ARG_het_region[13,3] <- ifelse(het_conurbano[7,4]<0.1,paste0(het_conurbano[7,2],"*"),het_conurbano[7,2])
ARG_het_region[13,3] <- ifelse(het_conurbano[7,4]<0.05,paste0(het_conurbano[7,2],"**"),ARG_het_region[13,3])
ARG_het_region[13,3] <- ifelse(het_conurbano[7,4]<0.01,paste0(het_conurbano[7,2],"***"),ARG_het_region[13,3])

ARG_het_region[15,3] <- ifelse(het_conurbano[8,4]<0.1,paste0(het_conurbano[8,2],"*"),het_conurbano[8,2])
ARG_het_region[15,3] <- ifelse(het_conurbano[8,4]<0.05,paste0(het_conurbano[8,2],"**"),ARG_het_region[15,3])
ARG_het_region[15,3] <- ifelse(het_conurbano[8,4]<0.01,paste0(het_conurbano[8,2],"***"),ARG_het_region[15,3])

ARG_het_region[2,3] <- paste0("(",het_conurbano[1,3],")")
ARG_het_region[4,3] <- paste0("(",het_conurbano[2,3],")")
ARG_het_region[6,3] <- paste0("(",het_conurbano[3,3],")")
ARG_het_region[8,3] <- paste0("(",het_conurbano[4,3],")")
ARG_het_region[10,3] <- paste0("(",het_conurbano[5,3],")")
ARG_het_region[12,3] <- paste0("(",het_conurbano[6,3],")")
ARG_het_region[14,3] <- paste0("(",het_conurbano[7,3],")")
ARG_het_region[16,3] <- paste0("(",het_conurbano[8,3],")")

het_interact_region[,2] <- as.numeric(as.character(het_interact_region[,2]))
het_interact_region[,3] <- as.numeric(as.character(het_interact_region[,3]))
het_interact_region[,4] <- as.numeric(as.character(het_interact_region[,4]))

ARG_het_region[17,4] <- "Interaction Term"
ARG_het_region[1,4] <- ifelse(het_interact_region[1,4]<0.1,paste0(het_interact_region[1,2],"*"),het_interact_region[1,2])
ARG_het_region[1,4] <- ifelse(het_interact_region[1,4]<0.05,paste0(het_interact_region[1,2],"**"),ARG_het_region[1,4])
ARG_het_region[1,4] <- ifelse(het_interact_region[1,4]<0.01,paste0(het_interact_region[1,2],"***"),ARG_het_region[1,4])

ARG_het_region[3,4] <- ifelse(het_interact_region[2,4]<0.1,paste0(het_interact_region[2,2],"*"),het_interact_region[2,2])
ARG_het_region[3,4] <- ifelse(het_interact_region[2,4]<0.05,paste0(het_interact_region[2,2],"**"),ARG_het_region[3,4])
ARG_het_region[3,4] <- ifelse(het_interact_region[2,4]<0.01,paste0(het_interact_region[2,2],"***"),ARG_het_region[3,4])

ARG_het_region[5,4] <- ifelse(het_interact_region[3,4]<0.1,paste0(het_interact_region[3,2],"*"),het_interact_region[3,2])
ARG_het_region[5,4] <- ifelse(het_interact_region[3,4]<0.05,paste0(het_interact_region[3,2],"**"),ARG_het_region[5,4])
ARG_het_region[5,4] <- ifelse(het_interact_region[3,4]<0.01,paste0(het_interact_region[3,2],"***"),ARG_het_region[5,4])

ARG_het_region[7,4] <- ifelse(het_interact_region[4,4]<0.1,paste0(het_interact_region[4,2],"*"),het_interact_region[4,2])
ARG_het_region[7,4] <- ifelse(het_interact_region[4,4]<0.05,paste0(het_interact_region[4,2],"**"),ARG_het_region[7,4])
ARG_het_region[7,4] <- ifelse(het_interact_region[4,4]<0.01,paste0(het_interact_region[4,2],"***"),ARG_het_region[7,4])

ARG_het_region[9,4] <- ifelse(het_interact_region[5,4]<0.1,paste0(het_interact_region[5,2],"*"),het_interact_region[5,2])
ARG_het_region[9,4] <- ifelse(het_interact_region[5,4]<0.05,paste0(het_interact_region[5,2],"**"),ARG_het_region[9,4])
ARG_het_region[9,4] <- ifelse(het_interact_region[5,4]<0.01,paste0(het_interact_region[5,2],"***"),ARG_het_region[9,4])

ARG_het_region[11,4] <- ifelse(het_interact_region[6,4]<0.1,paste0(het_interact_region[6,2],"*"),het_interact_region[6,2])
ARG_het_region[11,4] <- ifelse(het_interact_region[6,4]<0.05,paste0(het_interact_region[6,2],"**"),ARG_het_region[11,4])
ARG_het_region[11,4] <- ifelse(het_interact_region[6,4]<0.01,paste0(het_interact_region[6,2],"***"),ARG_het_region[11,4])

ARG_het_region[13,4] <- ifelse(het_interact_region[7,4]<0.1,paste0(het_interact_region[7,2],"*"),het_interact_region[7,2])
ARG_het_region[13,4] <- ifelse(het_interact_region[7,4]<0.05,paste0(het_interact_region[7,2],"**"),ARG_het_region[13,4])
ARG_het_region[13,4] <- ifelse(het_interact_region[7,4]<0.01,paste0(het_interact_region[7,2],"***"),ARG_het_region[13,4])

ARG_het_region[15,4] <- ifelse(het_interact_region[8,4]<0.1,paste0(het_interact_region[8,2],"*"),het_interact_region[8,2])
ARG_het_region[15,4] <- ifelse(het_interact_region[8,4]<0.05,paste0(het_interact_region[8,2],"**"),ARG_het_region[15,4])
ARG_het_region[15,4] <- ifelse(het_interact_region[8,4]<0.01,paste0(het_interact_region[8,2],"***"),ARG_het_region[15,4])

ARG_het_region[2,4] <- paste0("(",het_interact_region[1,3],")")
ARG_het_region[4,4] <- paste0("(",het_interact_region[2,3],")")
ARG_het_region[6,4] <- paste0("(",het_interact_region[3,3],")")
ARG_het_region[8,4] <- paste0("(",het_interact_region[4,3],")")
ARG_het_region[10,4] <- paste0("(",het_interact_region[5,3],")")
ARG_het_region[12,4] <- paste0("(",het_interact_region[6,3],")")
ARG_het_region[14,4] <- paste0("(",het_interact_region[7,3],")")
ARG_het_region[16,4] <- paste0("(",het_interact_region[8,3],")")

ARG_het_region

#Table A13:
stargazer(as.matrix(ARG_het_region), rownames=F, out="TableA13.tex")


###by age:
##Table A16:

##age_1:
age_1 <- subset(ARG, ARG$age<41) #below median age:

outcomes_age_1 <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_1))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_1,age_1$treat7==0|age_1$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_age_1) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_age_1 <- outcomes_age_1[,c(1,3,4:6)]
het_age_1[,2] <- round(as.numeric(het_age_1[,2]),3)
het_age_1[,3] <- round(as.numeric(het_age_1[,3]),3)
het_age_1[,4] <- round(as.numeric(het_age_1[,4]),3) 

het_age_1 <- as.data.frame(het_age_1[c(1:4,7:10),])

het_age_1[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_age_1) <- c("Variable","Effect","SE","p Value", "N")

het_age_1


##age_2:
age_2 <- subset(ARG, ARG$age>40)

outcomes_age_2 <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=age_2))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(age_2,age_2$treat7==0|age_2$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_age_2) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_age_2 <- outcomes_age_2[,c(1,3,4:6)]
het_age_2[,2] <- round(as.numeric(het_age_2[,2]),3)
het_age_2[,3] <- round(as.numeric(het_age_2[,3]),3)
het_age_2[,4] <- round(as.numeric(het_age_2[,4]),3) 

het_age_2 <- as.data.frame(het_age_2[c(1:4,7:10),])

het_age_2[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_age_2) <- c("Variable","Effect","SE","p Value", "N")

het_age_2


##interact_age:
valid_age <- subset(ARG, !is.na(age))

outcomes_interact_age <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 * age + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_age))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_age,valid_age$treat7==0|valid_age$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_interact_age) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_interact_age <- outcomes_interact_age[,c(1,3,4:6)]
het_interact_age[,2] <- round(as.numeric(het_interact_age[,2]),3)
het_interact_age[,3] <- round(as.numeric(het_interact_age[,3]),3)
het_interact_age[,4] <- round(as.numeric(het_interact_age[,4]),3) 

het_interact_age <- as.data.frame(het_interact_age[c(1:4,7:10),])

het_interact_age[,1] <-  c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_interact_age) <- c("Variable","Effect","SE","p Value", "N")

het_interact_age


##combine the output for the different subgroup analyses & interaction term:
ARG_het_age <- as.data.frame(cbind(rep(NA,2*nrow(het_age_1)),rep(NA,2*nrow(het_age_1)),rep(NA,2*nrow(het_age_1)),rep(NA,2*nrow(het_age_1))))

ARG_het_age[1,1] <- het_age_1[1,1]
ARG_het_age[2,1] <- ""
ARG_het_age[3,1] <- het_age_1[2,1]
ARG_het_age[4,1] <- ""
ARG_het_age[5,1] <- het_age_1[3,1]
ARG_het_age[6,1] <- ""
ARG_het_age[7,1] <- het_age_1[4,1]
ARG_het_age[8,1] <- ""
ARG_het_age[9,1] <- het_age_1[5,1]
ARG_het_age[10,1] <- ""
ARG_het_age[11,1] <- het_age_1[6,1]
ARG_het_age[12,1] <- ""
ARG_het_age[13,1] <- het_age_1[7,1]
ARG_het_age[14,1] <- ""
ARG_het_age[15,1] <- het_age_1[8,1]
ARG_het_age[16,1] <- ""
ARG_het_age[17,1] <- "Sample"

het_age_1[,2] <- as.numeric(as.character(het_age_1[,2]))
het_age_1[,3] <- as.numeric(as.character(het_age_1[,3]))
het_age_1[,4] <- as.numeric(as.character(het_age_1[,4]))

ARG_het_age[17,2] <- "Young"
ARG_het_age[1,2] <- ifelse(het_age_1[1,4]<0.1,paste0(het_age_1[1,2],"*"),het_age_1[1,2])
ARG_het_age[1,2] <- ifelse(het_age_1[1,4]<0.05,paste0(het_age_1[1,2],"**"),ARG_het_age[1,2])
ARG_het_age[1,2] <- ifelse(het_age_1[1,4]<0.01,paste0(het_age_1[1,2],"***"),ARG_het_age[1,2])

ARG_het_age[3,2] <- ifelse(het_age_1[2,4]<0.1,paste0(het_age_1[2,2],"*"),het_age_1[2,2])
ARG_het_age[3,2] <- ifelse(het_age_1[2,4]<0.05,paste0(het_age_1[2,2],"**"),ARG_het_age[3,2])
ARG_het_age[3,2] <- ifelse(het_age_1[2,4]<0.01,paste0(het_age_1[2,2],"***"),ARG_het_age[3,2])

ARG_het_age[5,2] <- ifelse(het_age_1[3,4]<0.1,paste0(het_age_1[3,2],"*"),het_age_1[3,2])
ARG_het_age[5,2] <- ifelse(het_age_1[3,4]<0.05,paste0(het_age_1[3,2],"**"),ARG_het_age[5,2])
ARG_het_age[5,2] <- ifelse(het_age_1[3,4]<0.01,paste0(het_age_1[3,2],"***"),ARG_het_age[5,2])

ARG_het_age[7,2] <- ifelse(het_age_1[4,4]<0.1,paste0(het_age_1[4,2],"*"),het_age_1[4,2])
ARG_het_age[7,2] <- ifelse(het_age_1[4,4]<0.05,paste0(het_age_1[4,2],"**"),ARG_het_age[7,2])
ARG_het_age[7,2] <- ifelse(het_age_1[4,4]<0.01,paste0(het_age_1[4,2],"***"),ARG_het_age[7,2])

ARG_het_age[9,2] <- ifelse(het_age_1[5,4]<0.1,paste0(het_age_1[5,2],"*"),het_age_1[5,2])
ARG_het_age[9,2] <- ifelse(het_age_1[5,4]<0.05,paste0(het_age_1[5,2],"**"),ARG_het_age[9,2])
ARG_het_age[9,2] <- ifelse(het_age_1[5,4]<0.01,paste0(het_age_1[5,2],"***"),ARG_het_age[9,2])

ARG_het_age[11,2] <- ifelse(het_age_1[6,4]<0.1,paste0(het_age_1[6,2],"*"),het_age_1[6,2])
ARG_het_age[11,2] <- ifelse(het_age_1[6,4]<0.05,paste0(het_age_1[6,2],"**"),ARG_het_age[11,2])
ARG_het_age[11,2] <- ifelse(het_age_1[6,4]<0.01,paste0(het_age_1[6,2],"***"),ARG_het_age[11,2])

ARG_het_age[13,2] <- ifelse(het_age_1[7,4]<0.1,paste0(het_age_1[7,2],"*"),het_age_1[7,2])
ARG_het_age[13,2] <- ifelse(het_age_1[7,4]<0.05,paste0(het_age_1[7,2],"**"),ARG_het_age[13,2])
ARG_het_age[13,2] <- ifelse(het_age_1[7,4]<0.01,paste0(het_age_1[7,2],"***"),ARG_het_age[13,2])

ARG_het_age[15,2] <- ifelse(het_age_1[8,4]<0.1,paste0(het_age_1[8,2],"*"),het_age_1[8,2])
ARG_het_age[15,2] <- ifelse(het_age_1[8,4]<0.05,paste0(het_age_1[8,2],"**"),ARG_het_age[15,2])
ARG_het_age[15,2] <- ifelse(het_age_1[8,4]<0.01,paste0(het_age_1[8,2],"***"),ARG_het_age[15,2])

ARG_het_age[2,2] <- paste0("(",het_age_1[1,3],")")
ARG_het_age[4,2] <- paste0("(",het_age_1[2,3],")")
ARG_het_age[6,2] <- paste0("(",het_age_1[3,3],")")
ARG_het_age[8,2] <- paste0("(",het_age_1[4,3],")")
ARG_het_age[10,2] <- paste0("(",het_age_1[5,3],")")
ARG_het_age[12,2] <- paste0("(",het_age_1[6,3],")")
ARG_het_age[14,2] <- paste0("(",het_age_1[7,3],")")
ARG_het_age[16,2] <- paste0("(",het_age_1[8,3],")")

het_age_2[,2] <- as.numeric(as.character(het_age_2[,2]))
het_age_2[,3] <- as.numeric(as.character(het_age_2[,3]))
het_age_2[,4] <- as.numeric(as.character(het_age_2[,4]))

ARG_het_age[17,3] <- "Old"
ARG_het_age[1,3] <- ifelse(het_age_2[1,4]<0.1,paste0(het_age_2[1,2],"*"),het_age_2[1,2])
ARG_het_age[1,3] <- ifelse(het_age_2[1,4]<0.05,paste0(het_age_2[1,2],"**"),ARG_het_age[1,3])
ARG_het_age[1,3] <- ifelse(het_age_2[1,4]<0.01,paste0(het_age_2[1,2],"***"),ARG_het_age[1,3])

ARG_het_age[3,3] <- ifelse(het_age_2[2,4]<0.1,paste0(het_age_2[2,2],"*"),het_age_2[2,2])
ARG_het_age[3,3] <- ifelse(het_age_2[2,4]<0.05,paste0(het_age_2[2,2],"**"),ARG_het_age[3,3])
ARG_het_age[3,3] <- ifelse(het_age_2[2,4]<0.01,paste0(het_age_2[2,2],"***"),ARG_het_age[3,3])

ARG_het_age[5,3] <- ifelse(het_age_2[3,4]<0.1,paste0(het_age_2[3,2],"*"),het_age_2[3,2])
ARG_het_age[5,3] <- ifelse(het_age_2[3,4]<0.05,paste0(het_age_2[3,2],"**"),ARG_het_age[5,3])
ARG_het_age[5,3] <- ifelse(het_age_2[3,4]<0.01,paste0(het_age_2[3,2],"***"),ARG_het_age[5,3])

ARG_het_age[7,3] <- ifelse(het_age_2[4,4]<0.1,paste0(het_age_2[4,2],"*"),het_age_2[4,2])
ARG_het_age[7,3] <- ifelse(het_age_2[4,4]<0.05,paste0(het_age_2[4,2],"**"),ARG_het_age[7,3])
ARG_het_age[7,3] <- ifelse(het_age_2[4,4]<0.01,paste0(het_age_2[4,2],"***"),ARG_het_age[7,3])

ARG_het_age[9,3] <- ifelse(het_age_2[5,4]<0.1,paste0(het_age_2[5,2],"*"),het_age_2[5,2])
ARG_het_age[9,3] <- ifelse(het_age_2[5,4]<0.05,paste0(het_age_2[5,2],"**"),ARG_het_age[9,3])
ARG_het_age[9,3] <- ifelse(het_age_2[5,4]<0.01,paste0(het_age_2[5,2],"***"),ARG_het_age[9,3])

ARG_het_age[11,3] <- ifelse(het_age_2[6,4]<0.1,paste0(het_age_2[6,2],"*"),het_age_2[6,2])
ARG_het_age[11,3] <- ifelse(het_age_2[6,4]<0.05,paste0(het_age_2[6,2],"**"),ARG_het_age[11,3])
ARG_het_age[11,3] <- ifelse(het_age_2[6,4]<0.01,paste0(het_age_2[6,2],"***"),ARG_het_age[11,3])

ARG_het_age[13,3] <- ifelse(het_age_2[7,4]<0.1,paste0(het_age_2[7,2],"*"),het_age_2[7,2])
ARG_het_age[13,3] <- ifelse(het_age_2[7,4]<0.05,paste0(het_age_2[7,2],"**"),ARG_het_age[13,3])
ARG_het_age[13,3] <- ifelse(het_age_2[7,4]<0.01,paste0(het_age_2[7,2],"***"),ARG_het_age[13,3])

ARG_het_age[15,3] <- ifelse(het_age_2[8,4]<0.1,paste0(het_age_2[8,2],"*"),het_age_2[8,2])
ARG_het_age[15,3] <- ifelse(het_age_2[8,4]<0.05,paste0(het_age_2[8,2],"**"),ARG_het_age[15,3])
ARG_het_age[15,3] <- ifelse(het_age_2[8,4]<0.01,paste0(het_age_2[8,2],"***"),ARG_het_age[15,3])

ARG_het_age[2,3] <- paste0("(",het_age_2[1,3],")")
ARG_het_age[4,3] <- paste0("(",het_age_2[2,3],")")
ARG_het_age[6,3] <- paste0("(",het_age_2[3,3],")")
ARG_het_age[8,3] <- paste0("(",het_age_2[4,3],")")
ARG_het_age[10,3] <- paste0("(",het_age_2[5,3],")")
ARG_het_age[12,3] <- paste0("(",het_age_2[6,3],")")
ARG_het_age[14,3] <- paste0("(",het_age_2[7,3],")")
ARG_het_age[16,3] <- paste0("(",het_age_2[8,3],")")

het_interact_age[,2] <- as.numeric(as.character(het_interact_age[,2]))
het_interact_age[,3] <- as.numeric(as.character(het_interact_age[,3]))
het_interact_age[,4] <- as.numeric(as.character(het_interact_age[,4]))

ARG_het_age[17,4] <- "Interaction Term"
ARG_het_age[1,4] <- ifelse(het_interact_age[1,4]<0.1,paste0(het_interact_age[1,2],"*"),het_interact_age[1,2])
ARG_het_age[1,4] <- ifelse(het_interact_age[1,4]<0.05,paste0(het_interact_age[1,2],"**"),ARG_het_age[1,4])
ARG_het_age[1,4] <- ifelse(het_interact_age[1,4]<0.01,paste0(het_interact_age[1,2],"***"),ARG_het_age[1,4])

ARG_het_age[3,4] <- ifelse(het_interact_age[2,4]<0.1,paste0(het_interact_age[2,2],"*"),het_interact_age[2,2])
ARG_het_age[3,4] <- ifelse(het_interact_age[2,4]<0.05,paste0(het_interact_age[2,2],"**"),ARG_het_age[3,4])
ARG_het_age[3,4] <- ifelse(het_interact_age[2,4]<0.01,paste0(het_interact_age[2,2],"***"),ARG_het_age[3,4])

ARG_het_age[5,4] <- ifelse(het_interact_age[3,4]<0.1,paste0(het_interact_age[3,2],"*"),het_interact_age[3,2])
ARG_het_age[5,4] <- ifelse(het_interact_age[3,4]<0.05,paste0(het_interact_age[3,2],"**"),ARG_het_age[5,4])
ARG_het_age[5,4] <- ifelse(het_interact_age[3,4]<0.01,paste0(het_interact_age[3,2],"***"),ARG_het_age[5,4])

ARG_het_age[7,4] <- ifelse(het_interact_age[4,4]<0.1,paste0(het_interact_age[4,2],"*"),het_interact_age[4,2])
ARG_het_age[7,4] <- ifelse(het_interact_age[4,4]<0.05,paste0(het_interact_age[4,2],"**"),ARG_het_age[7,4])
ARG_het_age[7,4] <- ifelse(het_interact_age[4,4]<0.01,paste0(het_interact_age[4,2],"***"),ARG_het_age[7,4])

ARG_het_age[9,4] <- ifelse(het_interact_age[5,4]<0.1,paste0(het_interact_age[5,2],"*"),het_interact_age[5,2])
ARG_het_age[9,4] <- ifelse(het_interact_age[5,4]<0.05,paste0(het_interact_age[5,2],"**"),ARG_het_age[9,4])
ARG_het_age[9,4] <- ifelse(het_interact_age[5,4]<0.01,paste0(het_interact_age[5,2],"***"),ARG_het_age[9,4])

ARG_het_age[11,4] <- ifelse(het_interact_age[6,4]<0.1,paste0(het_interact_age[6,2],"*"),het_interact_age[6,2])
ARG_het_age[11,4] <- ifelse(het_interact_age[6,4]<0.05,paste0(het_interact_age[6,2],"**"),ARG_het_age[11,4])
ARG_het_age[11,4] <- ifelse(het_interact_age[6,4]<0.01,paste0(het_interact_age[6,2],"***"),ARG_het_age[11,4])

ARG_het_age[13,4] <- ifelse(het_interact_age[7,4]<0.1,paste0(het_interact_age[7,2],"*"),het_interact_age[7,2])
ARG_het_age[13,4] <- ifelse(het_interact_age[7,4]<0.05,paste0(het_interact_age[7,2],"**"),ARG_het_age[13,4])
ARG_het_age[13,4] <- ifelse(het_interact_age[7,4]<0.01,paste0(het_interact_age[7,2],"***"),ARG_het_age[13,4])

ARG_het_age[15,4] <- ifelse(het_interact_age[8,4]<0.1,paste0(het_interact_age[8,2],"*"),het_interact_age[8,2])
ARG_het_age[15,4] <- ifelse(het_interact_age[8,4]<0.05,paste0(het_interact_age[8,2],"**"),ARG_het_age[15,4])
ARG_het_age[15,4] <- ifelse(het_interact_age[8,4]<0.01,paste0(het_interact_age[8,2],"***"),ARG_het_age[15,4])

ARG_het_age[2,4] <- paste0("(",het_interact_age[1,3],")")
ARG_het_age[4,4] <- paste0("(",het_interact_age[2,3],")")
ARG_het_age[6,4] <- paste0("(",het_interact_age[3,3],")")
ARG_het_age[8,4] <- paste0("(",het_interact_age[4,3],")")
ARG_het_age[10,4] <- paste0("(",het_interact_age[5,3],")")
ARG_het_age[12,4] <- paste0("(",het_interact_age[6,3],")")
ARG_het_age[14,4] <- paste0("(",het_interact_age[7,3],")")
ARG_het_age[16,4] <- paste0("(",het_interact_age[8,3],")")

ARG_het_age

#Table A16:
stargazer(as.matrix(ARG_het_age), rownames=F, out="TableA16.tex")


###by past voting status:
##Table A15:

##voted_not_past:
voted_not_past <- subset(ARG, ARG$voted==0)

outcomes_voted_not_past <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_not_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_not_past,voted_not_past$treat7==0|voted_not_past$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_voted_not_past) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_voted_not_past <- outcomes_voted_not_past[,c(1,3,4:6)]
het_voted_not_past[,2] <- round(as.numeric(het_voted_not_past[,2]),3)
het_voted_not_past[,3] <- round(as.numeric(het_voted_not_past[,3]),3)
het_voted_not_past[,4] <- round(as.numeric(het_voted_not_past[,4]),3) 

het_voted_not_past <- as.data.frame(het_voted_not_past[c(1:4,7:10),])

het_voted_not_past[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_voted_not_past) <- c("Variable","Effect","SE","p Value", "N")

het_voted_not_past


##voted_past:
voted_past <- subset(ARG, ARG$voted==1)

outcomes_voted_past <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=voted_past))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(voted_past,voted_past$treat7==0|voted_past$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_voted_past) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_voted_past <- outcomes_voted_past[,c(1,3,4:6)]
het_voted_past[,2] <- round(as.numeric(het_voted_past[,2]),3)
het_voted_past[,3] <- round(as.numeric(het_voted_past[,3]),3)
het_voted_past[,4] <- round(as.numeric(het_voted_past[,4]),3) 

het_voted_past <- as.data.frame(het_voted_past[c(1:4,7:10),])

het_voted_past[,1] <-  c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_voted_past) <- c("Variable","Effect","SE","p Value", "N")

het_voted_past


##interact_voted_past:
valid_voted_past <- subset(ARG, !is.na(voted))

outcomes_interact_voted_past <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$progcorrupt),1,0))
    ),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$solvecorrupt),1,0))
    ),
  c("corrupt",
    summary(lm(corrupt ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(corrupt ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$corrupt),1,0))
    ),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$demonstrate_willingness),1,0))
    ),
  c("vote_null",
    summary(lm(vote_null ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(vote_null ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$vote_null),1,0))
    ),
  c("vote_not",
    summary(lm(vote_not ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(vote_not ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$vote_not),1,0))
    ),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$vote_invalid),1,0))
    ),
  c("conf_judge",
    summary(lm(conf_judge ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(conf_judge ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$conf_judge),1,0))
    ),
  c("conf_parties",
    summary(lm(conf_parties ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(conf_parties ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$conf_parties),1,0))
    ),
  c("conf_parl",
    summary(lm(conf_parl ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[1,1],
    summary(lm(conf_parl ~ treat7 * voted + treat7 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=valid_voted_past))$coefficients[32,][c(1,2,4)],
    sum(ifelse(!is.na(subset(valid_voted_past,valid_voted_past$treat7==0|valid_voted_past$treat7==1)$conf_parl),1,0))
    ))

colnames(outcomes_interact_voted_past) <- c("Variable","Intercept7","Estimate7","SE7","pvalue7","ValidN7")

het_interact_voted_past <- outcomes_interact_voted_past[,c(1,3,4:6)]
het_interact_voted_past[,2] <- round(as.numeric(het_interact_voted_past[,2]),3)
het_interact_voted_past[,3] <- round(as.numeric(het_interact_voted_past[,3]),3)
het_interact_voted_past[,4] <- round(as.numeric(het_interact_voted_past[,4]),3) 

het_interact_voted_past <- as.data.frame(het_interact_voted_past[c(1:4,7:10),])

het_interact_voted_past[,1] <-  c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

colnames(het_interact_voted_past) <- c("Variable","Effect","SE","p Value", "N")

het_interact_voted_past


##combine the output for the different subgroup analyses & interaction term:
ARG_het_voted_past <- as.data.frame(cbind(rep(NA,2*nrow(het_voted_not_past)),rep(NA,2*nrow(het_voted_not_past)),rep(NA,2*nrow(het_voted_not_past)),rep(NA,2*nrow(het_voted_not_past))))

ARG_het_voted_past[1,1] <- het_voted_not_past[1,1]
ARG_het_voted_past[2,1] <- ""
ARG_het_voted_past[3,1] <- het_voted_not_past[2,1]
ARG_het_voted_past[4,1] <- ""
ARG_het_voted_past[5,1] <- het_voted_not_past[3,1]
ARG_het_voted_past[6,1] <- ""
ARG_het_voted_past[7,1] <- het_voted_not_past[4,1]
ARG_het_voted_past[8,1] <- ""
ARG_het_voted_past[9,1] <- het_voted_not_past[5,1]
ARG_het_voted_past[10,1] <- ""
ARG_het_voted_past[11,1] <- het_voted_not_past[6,1]
ARG_het_voted_past[12,1] <- ""
ARG_het_voted_past[13,1] <- het_voted_not_past[7,1]
ARG_het_voted_past[14,1] <- ""
ARG_het_voted_past[15,1] <- het_voted_not_past[8,1]
ARG_het_voted_past[16,1] <- ""
ARG_het_voted_past[17,1] <- "Sample"

het_voted_not_past[,2] <- as.numeric(as.character(het_voted_not_past[,2]))
het_voted_not_past[,3] <- as.numeric(as.character(het_voted_not_past[,3]))
het_voted_not_past[,4] <- as.numeric(as.character(het_voted_not_past[,4]))

ARG_het_voted_past[17,2] <- "Previous Non Voters"
ARG_het_voted_past[1,2] <- ifelse(het_voted_not_past[1,4]<0.1,paste0(het_voted_not_past[1,2],"*"),het_voted_not_past[1,2])
ARG_het_voted_past[1,2] <- ifelse(het_voted_not_past[1,4]<0.05,paste0(het_voted_not_past[1,2],"**"),ARG_het_voted_past[1,2])
ARG_het_voted_past[1,2] <- ifelse(het_voted_not_past[1,4]<0.01,paste0(het_voted_not_past[1,2],"***"),ARG_het_voted_past[1,2])

ARG_het_voted_past[3,2] <- ifelse(het_voted_not_past[2,4]<0.1,paste0(het_voted_not_past[2,2],"*"),het_voted_not_past[2,2])
ARG_het_voted_past[3,2] <- ifelse(het_voted_not_past[2,4]<0.05,paste0(het_voted_not_past[2,2],"**"),ARG_het_voted_past[3,2])
ARG_het_voted_past[3,2] <- ifelse(het_voted_not_past[2,4]<0.01,paste0(het_voted_not_past[2,2],"***"),ARG_het_voted_past[3,2])

ARG_het_voted_past[5,2] <- ifelse(het_voted_not_past[3,4]<0.1,paste0(het_voted_not_past[3,2],"*"),het_voted_not_past[3,2])
ARG_het_voted_past[5,2] <- ifelse(het_voted_not_past[3,4]<0.05,paste0(het_voted_not_past[3,2],"**"),ARG_het_voted_past[5,2])
ARG_het_voted_past[5,2] <- ifelse(het_voted_not_past[3,4]<0.01,paste0(het_voted_not_past[3,2],"***"),ARG_het_voted_past[5,2])

ARG_het_voted_past[7,2] <- ifelse(het_voted_not_past[4,4]<0.1,paste0(het_voted_not_past[4,2],"*"),het_voted_not_past[4,2])
ARG_het_voted_past[7,2] <- ifelse(het_voted_not_past[4,4]<0.05,paste0(het_voted_not_past[4,2],"**"),ARG_het_voted_past[7,2])
ARG_het_voted_past[7,2] <- ifelse(het_voted_not_past[4,4]<0.01,paste0(het_voted_not_past[4,2],"***"),ARG_het_voted_past[7,2])

ARG_het_voted_past[9,2] <- ifelse(het_voted_not_past[5,4]<0.1,paste0(het_voted_not_past[5,2],"*"),het_voted_not_past[5,2])
ARG_het_voted_past[9,2] <- ifelse(het_voted_not_past[5,4]<0.05,paste0(het_voted_not_past[5,2],"**"),ARG_het_voted_past[9,2])
ARG_het_voted_past[9,2] <- ifelse(het_voted_not_past[5,4]<0.01,paste0(het_voted_not_past[5,2],"***"),ARG_het_voted_past[9,2])

ARG_het_voted_past[11,2] <- ifelse(het_voted_not_past[6,4]<0.1,paste0(het_voted_not_past[6,2],"*"),het_voted_not_past[6,2])
ARG_het_voted_past[11,2] <- ifelse(het_voted_not_past[6,4]<0.05,paste0(het_voted_not_past[6,2],"**"),ARG_het_voted_past[11,2])
ARG_het_voted_past[11,2] <- ifelse(het_voted_not_past[6,4]<0.01,paste0(het_voted_not_past[6,2],"***"),ARG_het_voted_past[11,2])

ARG_het_voted_past[13,2] <- ifelse(het_voted_not_past[7,4]<0.1,paste0(het_voted_not_past[7,2],"*"),het_voted_not_past[7,2])
ARG_het_voted_past[13,2] <- ifelse(het_voted_not_past[7,4]<0.05,paste0(het_voted_not_past[7,2],"**"),ARG_het_voted_past[13,2])
ARG_het_voted_past[13,2] <- ifelse(het_voted_not_past[7,4]<0.01,paste0(het_voted_not_past[7,2],"***"),ARG_het_voted_past[13,2])

ARG_het_voted_past[15,2] <- ifelse(het_voted_not_past[8,4]<0.1,paste0(het_voted_not_past[8,2],"*"),het_voted_not_past[8,2])
ARG_het_voted_past[15,2] <- ifelse(het_voted_not_past[8,4]<0.05,paste0(het_voted_not_past[8,2],"**"),ARG_het_voted_past[15,2])
ARG_het_voted_past[15,2] <- ifelse(het_voted_not_past[8,4]<0.01,paste0(het_voted_not_past[8,2],"***"),ARG_het_voted_past[15,2])

ARG_het_voted_past[2,2] <- paste0("(",het_voted_not_past[1,3],")")
ARG_het_voted_past[4,2] <- paste0("(",het_voted_not_past[2,3],")")
ARG_het_voted_past[6,2] <- paste0("(",het_voted_not_past[3,3],")")
ARG_het_voted_past[8,2] <- paste0("(",het_voted_not_past[4,3],")")
ARG_het_voted_past[10,2] <- paste0("(",het_voted_not_past[5,3],")")
ARG_het_voted_past[12,2] <- paste0("(",het_voted_not_past[6,3],")")
ARG_het_voted_past[14,2] <- paste0("(",het_voted_not_past[7,3],")")
ARG_het_voted_past[16,2] <- paste0("(",het_voted_not_past[8,3],")")

het_voted_past[,2] <- as.numeric(as.character(het_voted_past[,2]))
het_voted_past[,3] <- as.numeric(as.character(het_voted_past[,3]))
het_voted_past[,4] <- as.numeric(as.character(het_voted_past[,4]))

ARG_het_voted_past[17,3] <- "Previous Voters"
ARG_het_voted_past[1,3] <- ifelse(het_voted_past[1,4]<0.1,paste0(het_voted_past[1,2],"*"),het_voted_past[1,2])
ARG_het_voted_past[1,3] <- ifelse(het_voted_past[1,4]<0.05,paste0(het_voted_past[1,2],"**"),ARG_het_voted_past[1,3])
ARG_het_voted_past[1,3] <- ifelse(het_voted_past[1,4]<0.01,paste0(het_voted_past[1,2],"***"),ARG_het_voted_past[1,3])

ARG_het_voted_past[3,3] <- ifelse(het_voted_past[2,4]<0.1,paste0(het_voted_past[2,2],"*"),het_voted_past[2,2])
ARG_het_voted_past[3,3] <- ifelse(het_voted_past[2,4]<0.05,paste0(het_voted_past[2,2],"**"),ARG_het_voted_past[3,3])
ARG_het_voted_past[3,3] <- ifelse(het_voted_past[2,4]<0.01,paste0(het_voted_past[2,2],"***"),ARG_het_voted_past[3,3])

ARG_het_voted_past[5,3] <- ifelse(het_voted_past[3,4]<0.1,paste0(het_voted_past[3,2],"*"),het_voted_past[3,2])
ARG_het_voted_past[5,3] <- ifelse(het_voted_past[3,4]<0.05,paste0(het_voted_past[3,2],"**"),ARG_het_voted_past[5,3])
ARG_het_voted_past[5,3] <- ifelse(het_voted_past[3,4]<0.01,paste0(het_voted_past[3,2],"***"),ARG_het_voted_past[5,3])

ARG_het_voted_past[7,3] <- ifelse(het_voted_past[4,4]<0.1,paste0(het_voted_past[4,2],"*"),het_voted_past[4,2])
ARG_het_voted_past[7,3] <- ifelse(het_voted_past[4,4]<0.05,paste0(het_voted_past[4,2],"**"),ARG_het_voted_past[7,3])
ARG_het_voted_past[7,3] <- ifelse(het_voted_past[4,4]<0.01,paste0(het_voted_past[4,2],"***"),ARG_het_voted_past[7,3])

ARG_het_voted_past[9,3] <- ifelse(het_voted_past[5,4]<0.1,paste0(het_voted_past[5,2],"*"),het_voted_past[5,2])
ARG_het_voted_past[9,3] <- ifelse(het_voted_past[5,4]<0.05,paste0(het_voted_past[5,2],"**"),ARG_het_voted_past[9,3])
ARG_het_voted_past[9,3] <- ifelse(het_voted_past[5,4]<0.01,paste0(het_voted_past[5,2],"***"),ARG_het_voted_past[9,3])

ARG_het_voted_past[11,3] <- ifelse(het_voted_past[6,4]<0.1,paste0(het_voted_past[6,2],"*"),het_voted_past[6,2])
ARG_het_voted_past[11,3] <- ifelse(het_voted_past[6,4]<0.05,paste0(het_voted_past[6,2],"**"),ARG_het_voted_past[11,3])
ARG_het_voted_past[11,3] <- ifelse(het_voted_past[6,4]<0.01,paste0(het_voted_past[6,2],"***"),ARG_het_voted_past[11,3])

ARG_het_voted_past[13,3] <- ifelse(het_voted_past[7,4]<0.1,paste0(het_voted_past[7,2],"*"),het_voted_past[7,2])
ARG_het_voted_past[13,3] <- ifelse(het_voted_past[7,4]<0.05,paste0(het_voted_past[7,2],"**"),ARG_het_voted_past[13,3])
ARG_het_voted_past[13,3] <- ifelse(het_voted_past[7,4]<0.01,paste0(het_voted_past[7,2],"***"),ARG_het_voted_past[13,3])

ARG_het_voted_past[15,3] <- ifelse(het_voted_past[8,4]<0.1,paste0(het_voted_past[8,2],"*"),het_voted_past[8,2])
ARG_het_voted_past[15,3] <- ifelse(het_voted_past[8,4]<0.05,paste0(het_voted_past[8,2],"**"),ARG_het_voted_past[15,3])
ARG_het_voted_past[15,3] <- ifelse(het_voted_past[8,4]<0.01,paste0(het_voted_past[8,2],"***"),ARG_het_voted_past[15,3])

ARG_het_voted_past[2,3] <- paste0("(",het_voted_past[1,3],")")
ARG_het_voted_past[4,3] <- paste0("(",het_voted_past[2,3],")")
ARG_het_voted_past[6,3] <- paste0("(",het_voted_past[3,3],")")
ARG_het_voted_past[8,3] <- paste0("(",het_voted_past[4,3],")")
ARG_het_voted_past[10,3] <- paste0("(",het_voted_past[5,3],")")
ARG_het_voted_past[12,3] <- paste0("(",het_voted_past[6,3],")")
ARG_het_voted_past[14,3] <- paste0("(",het_voted_past[7,3],")")
ARG_het_voted_past[16,3] <- paste0("(",het_voted_past[8,3],")")

het_interact_voted_past[,2] <- as.numeric(as.character(het_interact_voted_past[,2]))
het_interact_voted_past[,3] <- as.numeric(as.character(het_interact_voted_past[,3]))
het_interact_voted_past[,4] <- as.numeric(as.character(het_interact_voted_past[,4]))

ARG_het_voted_past[17,4] <- "Interaction Term"
ARG_het_voted_past[1,4] <- ifelse(het_interact_voted_past[1,4]<0.1,paste0(het_interact_voted_past[1,2],"*"),het_interact_voted_past[1,2])
ARG_het_voted_past[1,4] <- ifelse(het_interact_voted_past[1,4]<0.05,paste0(het_interact_voted_past[1,2],"**"),ARG_het_voted_past[1,4])
ARG_het_voted_past[1,4] <- ifelse(het_interact_voted_past[1,4]<0.01,paste0(het_interact_voted_past[1,2],"***"),ARG_het_voted_past[1,4])

ARG_het_voted_past[3,4] <- ifelse(het_interact_voted_past[2,4]<0.1,paste0(het_interact_voted_past[2,2],"*"),het_interact_voted_past[2,2])
ARG_het_voted_past[3,4] <- ifelse(het_interact_voted_past[2,4]<0.05,paste0(het_interact_voted_past[2,2],"**"),ARG_het_voted_past[3,4])
ARG_het_voted_past[3,4] <- ifelse(het_interact_voted_past[2,4]<0.01,paste0(het_interact_voted_past[2,2],"***"),ARG_het_voted_past[3,4])

ARG_het_voted_past[5,4] <- ifelse(het_interact_voted_past[3,4]<0.1,paste0(het_interact_voted_past[3,2],"*"),het_interact_voted_past[3,2])
ARG_het_voted_past[5,4] <- ifelse(het_interact_voted_past[3,4]<0.05,paste0(het_interact_voted_past[3,2],"**"),ARG_het_voted_past[5,4])
ARG_het_voted_past[5,4] <- ifelse(het_interact_voted_past[3,4]<0.01,paste0(het_interact_voted_past[3,2],"***"),ARG_het_voted_past[5,4])

ARG_het_voted_past[7,4] <- ifelse(het_interact_voted_past[4,4]<0.1,paste0(het_interact_voted_past[4,2],"*"),het_interact_voted_past[4,2])
ARG_het_voted_past[7,4] <- ifelse(het_interact_voted_past[4,4]<0.05,paste0(het_interact_voted_past[4,2],"**"),ARG_het_voted_past[7,4])
ARG_het_voted_past[7,4] <- ifelse(het_interact_voted_past[4,4]<0.01,paste0(het_interact_voted_past[4,2],"***"),ARG_het_voted_past[7,4])

ARG_het_voted_past[9,4] <- ifelse(het_interact_voted_past[5,4]<0.1,paste0(het_interact_voted_past[5,2],"*"),het_interact_voted_past[5,2])
ARG_het_voted_past[9,4] <- ifelse(het_interact_voted_past[5,4]<0.05,paste0(het_interact_voted_past[5,2],"**"),ARG_het_voted_past[9,4])
ARG_het_voted_past[9,4] <- ifelse(het_interact_voted_past[5,4]<0.01,paste0(het_interact_voted_past[5,2],"***"),ARG_het_voted_past[9,4])

ARG_het_voted_past[11,4] <- ifelse(het_interact_voted_past[6,4]<0.1,paste0(het_interact_voted_past[6,2],"*"),het_interact_voted_past[6,2])
ARG_het_voted_past[11,4] <- ifelse(het_interact_voted_past[6,4]<0.05,paste0(het_interact_voted_past[6,2],"**"),ARG_het_voted_past[11,4])
ARG_het_voted_past[11,4] <- ifelse(het_interact_voted_past[6,4]<0.01,paste0(het_interact_voted_past[6,2],"***"),ARG_het_voted_past[11,4])

ARG_het_voted_past[13,4] <- ifelse(het_interact_voted_past[7,4]<0.1,paste0(het_interact_voted_past[7,2],"*"),het_interact_voted_past[7,2])
ARG_het_voted_past[13,4] <- ifelse(het_interact_voted_past[7,4]<0.05,paste0(het_interact_voted_past[7,2],"**"),ARG_het_voted_past[13,4])
ARG_het_voted_past[13,4] <- ifelse(het_interact_voted_past[7,4]<0.01,paste0(het_interact_voted_past[7,2],"***"),ARG_het_voted_past[13,4])

ARG_het_voted_past[15,4] <- ifelse(het_interact_voted_past[8,4]<0.1,paste0(het_interact_voted_past[8,2],"*"),het_interact_voted_past[8,2])
ARG_het_voted_past[15,4] <- ifelse(het_interact_voted_past[8,4]<0.05,paste0(het_interact_voted_past[8,2],"**"),ARG_het_voted_past[15,4])
ARG_het_voted_past[15,4] <- ifelse(het_interact_voted_past[8,4]<0.01,paste0(het_interact_voted_past[8,2],"***"),ARG_het_voted_past[15,4])

ARG_het_voted_past[2,4] <- paste0("(",het_interact_voted_past[1,3],")")
ARG_het_voted_past[4,4] <- paste0("(",het_interact_voted_past[2,3],")")
ARG_het_voted_past[6,4] <- paste0("(",het_interact_voted_past[3,3],")")
ARG_het_voted_past[8,4] <- paste0("(",het_interact_voted_past[4,3],")")
ARG_het_voted_past[10,4] <- paste0("(",het_interact_voted_past[5,3],")")
ARG_het_voted_past[12,4] <- paste0("(",het_interact_voted_past[6,3],")")
ARG_het_voted_past[14,4] <- paste0("(",het_interact_voted_past[7,3],")")
ARG_het_voted_past[16,4] <- paste0("(",het_interact_voted_past[8,3],")")

ARG_het_voted_past

#Table A15:
stargazer(as.matrix(ARG_het_voted_past), rownames=F, out="TableA15.tex")


###Sensitivity analysis: Dropping one province at a time

ARG_sensitivity_province <- data.frame(matrix(NA, nrow=(length(unique(ARG$reg))*8), ncol=6))
colnames(ARG_sensitivity_province) <- c("ProvinceDropped","Variable","Effect","SE","pValue","N")

for (i in 1:length(unique(ARG$reg))){
ARG_temp <- subset(ARG, ARG$reg!=unique(ARG$reg)[i])
  
outcomes_temp <- rbind(
  c("progcorrupt",
    summary(lm(progcorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[1,1],
    summary(lm(progcorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_temp,ARG_temp$treat14==0|ARG_temp$treat14==1)$progcorrupt),1,0))),
  c("solvecorrupt",
    summary(lm(solvecorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[1,1],
    summary(lm(solvecorrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_temp,ARG_temp$treat14==0|ARG_temp$treat14==1)$solvecorrupt),1,0))),
  c("corrupt",
    summary(lm(corrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[1,1],
    summary(lm(corrupt ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_temp,ARG_temp$treat14==0|ARG_temp$treat14==1)$corrupt),1,0))),
  c("demonstrate_willingness",
    summary(lm(demonstrate_willingness ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[1,1],
    summary(lm(demonstrate_willingness ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_temp,ARG_temp$treat14==0|ARG_temp$treat14==1)$demonstrate_willingness),1,0))),
  c("vote_invalid",
    summary(lm(vote_invalid ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[1,1],
    summary(lm(vote_invalid ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_temp,ARG_temp$treat14==0|ARG_temp$treat14==1)$vote_invalid),1,0))),
  c("conf_judge",
    summary(lm(conf_judge ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[1,1],
    summary(lm(conf_judge ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_temp,ARG_temp$treat14==0|ARG_temp$treat14==1)$conf_judge),1,0))),
  c("conf_parties",
    summary(lm(conf_parties ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[1,1],
    summary(lm(conf_parties ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_temp,ARG_temp$treat14==0|ARG_temp$treat14==1)$conf_parties),1,0))),
  c("conf_parl",
    summary(lm(conf_parl ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[1,1],
    summary(lm(conf_parl ~ treat14 + male + age + complete_highschool + university + laborforce + poverty + voted + factor(ciudad),data=ARG_temp))$coefficients[2,][c(1,2,4)],
    sum(ifelse(!is.na(subset(ARG_temp,ARG_temp$treat14==0|ARG_temp$treat14==1)$conf_parl),1,0)))
)

table_sens <- outcomes_temp[,c(1,3:6)]
table_sens <- as.matrix(table_sens)

table_sens[,1] <- c("Progress on state corruption","State's ability to solve corruption","Prevalence of corruption","Demonstrate","Invalid vote","Trust in judiciary","Trust in parties","Trust in congress")

table_sens <- cbind(rep(unique(ARG$reg)[i],8),table_sens)

ARG_sensitivity_province[c((i*8-7):(i*8)),] <- table_sens
}

ARG_sensitivity_province

ARG_sensitivity_province$Effect <- as.numeric(ARG_sensitivity_province$Effect)
ARG_sensitivity_province$SE <- as.numeric(ARG_sensitivity_province$SE)
ARG_sensitivity_province$pValue <- as.numeric(ARG_sensitivity_province$pValue)

ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32001"] <- "Capital Federal"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32101"] <- "Cuyo/Mendoza"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32201"] <- "Noreste/Chaco"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32202"] <- "Noreste/Corrientes"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32203"] <- "Noreste/Entre Ríos"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32207"] <- "Noroeste/Jujuy"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32209"] <- "Noroeste/Salta"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32211"] <- "Noroeste/Tucumán"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32301"] <- "Pampeana/Buenos Aires"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32302"] <- "Pampeana/Córdoba"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32303"] <- "Pampeana/La Pampa"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32304"] <- "Pampeana/Santa Fé"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32306"] <- "Patagónica/Neuquén"
ARG_sensitivity_province$ProvinceDropped[ARG_sensitivity_province$ProvinceDropped=="32307"] <- "Patagónica/Río Negro"

q1 <- ggplot(subset(ARG_sensitivity_province,Variable=="Progress on state corruption"), aes(y=Effect,x=ProvinceDropped)) +
  ggtitle("Progress on state corruption")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Treatment effect")+
  xlab("Region dropped")+
  theme(axis.text.x = element_text(angle = 0,vjust=0.5,hjust=0.5))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.25,0,0.25,0.5), limits=c(-0.7,0.7))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Effect + (SE*-qnorm((1-0.90)/2)), ymin=Effect - (SE*-qnorm((1-0.90)/2))), width=.4, position=position_dodge(.9),stat="identity",size=0.8)+ 
  geom_errorbar(aes(ymax=Effect + (SE*(-qnorm((1-0.95)/2))), ymin=Effect - (SE*(-qnorm((1-0.95)/2)))), width=.0, position=position_dodge(.9),stat="identity",size=0.8)+
  coord_flip()

q2 <- ggplot(subset(ARG_sensitivity_province,Variable=="State's ability to solve corruption"), aes(y=Effect,x=ProvinceDropped)) +
  ggtitle("State's ability to solve corruption")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Treatment effect")+
  xlab("Region dropped")+
  theme(axis.text.x = element_text(angle = 0,vjust=0.5,hjust=0.5))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.25,0,0.25,0.5), limits=c(-0.7,0.7))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Effect + (SE*-qnorm((1-0.90)/2)), ymin=Effect - (SE*-qnorm((1-0.90)/2))), width=.4, position=position_dodge(.9),stat="identity",size=0.8)+ 
  geom_errorbar(aes(ymax=Effect + (SE*(-qnorm((1-0.95)/2))), ymin=Effect - (SE*(-qnorm((1-0.95)/2)))), width=.0, position=position_dodge(.9),stat="identity",size=0.8)+
  coord_flip()

q3 <- ggplot(subset(ARG_sensitivity_province,Variable=="Prevalence of corruption"), aes(y=Effect,x=ProvinceDropped)) +
  ggtitle("Prevalence of corruption")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Treatment effect")+
  xlab("Region dropped")+
  theme(axis.text.x = element_text(angle = 0,vjust=0.5,hjust=0.5))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.25,0,0.25,0.5), limits=c(-0.7,0.7))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Effect + (SE*-qnorm((1-0.90)/2)), ymin=Effect - (SE*-qnorm((1-0.90)/2))), width=.4, position=position_dodge(.9),stat="identity",size=0.8)+ 
  geom_errorbar(aes(ymax=Effect + (SE*(-qnorm((1-0.95)/2))), ymin=Effect - (SE*(-qnorm((1-0.95)/2)))), width=.0, position=position_dodge(.9),stat="identity",size=0.8)+
  coord_flip()

q4 <- ggplot(subset(ARG_sensitivity_province,Variable=="Demonstrate"), aes(y=Effect,x=ProvinceDropped)) +
  ggtitle("Demonstrate")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Treatment effect")+
  xlab("Region dropped")+
  theme(axis.text.x = element_text(angle = 0,vjust=0.5,hjust=0.5))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.25,0,0.25,0.5), limits=c(-0.7,0.7))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Effect + (SE*-qnorm((1-0.90)/2)), ymin=Effect - (SE*-qnorm((1-0.90)/2))), width=.4, position=position_dodge(.9),stat="identity",size=0.8)+ 
  geom_errorbar(aes(ymax=Effect + (SE*(-qnorm((1-0.95)/2))), ymin=Effect - (SE*(-qnorm((1-0.95)/2)))), width=.0, position=position_dodge(.9),stat="identity",size=0.8)+
  coord_flip()

q5 <- ggplot(subset(ARG_sensitivity_province,Variable=="Invalid vote"), aes(y=Effect,x=ProvinceDropped)) +
  ggtitle("Invalid vote")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Treatment effect")+
  xlab("Region dropped")+
  theme(axis.text.x = element_text(angle = 0,vjust=0.5,hjust=0.5))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.25,0,0.25,0.5), limits=c(-0.7,0.7))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Effect + (SE*-qnorm((1-0.90)/2)), ymin=Effect - (SE*-qnorm((1-0.90)/2))), width=.4, position=position_dodge(.9),stat="identity",size=0.8)+ 
  geom_errorbar(aes(ymax=Effect + (SE*(-qnorm((1-0.95)/2))), ymin=Effect - (SE*(-qnorm((1-0.95)/2)))), width=.0, position=position_dodge(.9),stat="identity",size=0.8)+
  coord_flip()

q6 <- ggplot(subset(ARG_sensitivity_province,Variable=="Trust in judiciary"), aes(y=Effect,x=ProvinceDropped)) +
  ggtitle("Trust in judiciary")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Treatment effect")+
  xlab("Region dropped")+
  theme(axis.text.x = element_text(angle = 0,vjust=0.5,hjust=0.5))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.25,0,0.25,0.5), limits=c(-0.7,0.7))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Effect + (SE*-qnorm((1-0.90)/2)), ymin=Effect - (SE*-qnorm((1-0.90)/2))), width=.4, position=position_dodge(.9),stat="identity",size=0.8)+ 
  geom_errorbar(aes(ymax=Effect + (SE*(-qnorm((1-0.95)/2))), ymin=Effect - (SE*(-qnorm((1-0.95)/2)))), width=.0, position=position_dodge(.9),stat="identity",size=0.8)+
  coord_flip()

q7 <- ggplot(subset(ARG_sensitivity_province,Variable=="Trust in parties"), aes(y=Effect,x=ProvinceDropped)) +
  ggtitle("Trust in parties")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Treatment effect")+
  xlab("Region dropped")+
  theme(axis.text.x = element_text(angle = 0,vjust=0.5,hjust=0.5))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.25,0,0.25,0.5), limits=c(-0.7,0.7))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Effect + (SE*-qnorm((1-0.90)/2)), ymin=Effect - (SE*-qnorm((1-0.90)/2))), width=.4, position=position_dodge(.9),stat="identity",size=0.8)+ 
  geom_errorbar(aes(ymax=Effect + (SE*(-qnorm((1-0.95)/2))), ymin=Effect - (SE*(-qnorm((1-0.95)/2)))), width=.0, position=position_dodge(.9),stat="identity",size=0.8)+
  coord_flip()

q8 <- ggplot(subset(ARG_sensitivity_province,Variable=="Trust in congress"), aes(y=Effect,x=ProvinceDropped)) +
  ggtitle("Trust in congress")+
  theme(plot.title=element_text(size=16, face="bold", hjust=0.5))+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  geom_hline(yintercept=0, linetype="dotted",size=0.9)+
  ylab("Treatment effect")+
  xlab("Region dropped")+
  theme(axis.text.x = element_text(angle = 0,vjust=0.5,hjust=0.5))+
  scale_color_manual(values=c("darkblue", "red"))+
  theme(text=element_text(size=16))+
  theme(axis.text.y=element_text(size=16, color="black"))+
  theme(axis.text.x=element_text(size=16, color="black"))+
  theme(legend.position = "none",legend.title = element_blank())+
  scale_y_continuous(breaks=c(-0.5,-0.25,0,0.25,0.5), limits=c(-0.7,0.7))+
  geom_point(size=4,position = position_dodge(.9))+
  geom_errorbar(aes(ymax=Effect + (SE*-qnorm((1-0.90)/2)), ymin=Effect - (SE*-qnorm((1-0.90)/2))), width=.4, position=position_dodge(.9),stat="identity",size=0.8)+ 
  geom_errorbar(aes(ymax=Effect + (SE*(-qnorm((1-0.95)/2))), ymin=Effect - (SE*(-qnorm((1-0.95)/2)))), width=.0, position=position_dodge(.9),stat="identity",size=0.8)+
  coord_flip()


#Figure A4:
ARG_sensitivity_graph1 <- grid.arrange(q1, q2, q3, q4, ncol = 2)
ggsave("FigureA4.pdf", plot = ARG_sensitivity_graph1, width = 15, height = 15)


#Figure A5:
ARG_sensitivity_graph2 <- grid.arrange(q5, q6, q7, q8, ncol = 2)
ggsave("FigureA5.pdf", plot = ARG_sensitivity_graph2, width = 15, height = 15)

